更改三维图形颜色(matplotlib)

2024-10-01 13:43:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我在matplotlib中使用以下代码绘制了一个三维图形:

#Previously defines lists of data to plot...
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')

ax.set_axis_bgcolor('black')
ax.xaxis.label.set_color('white')
ax.yaxis.label.set_color('white')
ax.zaxis.label.set_color('white')
ax.tick_params(axis='x',colors='white')
ax.tick_params(axis='y',colors='white')
ax.tick_params(axis='z',colors='white')

ax.scatter(swasp_mag1,swasp_per1,swasp_age1,edgecolor='none',c='r',marker='o',s=35,label='SWASP')
ax.scatter(hyd_mag1,hyd_per1,hyd_age1,edgecolor='none',c='y',marker='o',s=35,label='Hyades')
ax.scatter(pld_mag1,pld_per1,pld_age1,edgecolor='none',c='b',marker='o',s=35,label='Pleiades')

ax.set_xlabel('B-V [mag]')
ax.set_ylabel('Period [days]')
ax.set_zlabel('Age [Myr]')

ax.set_xlim(0.495,1.6)
ax.set_ylim(0,30)
ax.set_zlim(0,600)

ax.legend(scatterpoints=1)
plt.show()

当我运行这个程序时,我得到以下结果: enter image description here

我已经将背景更改为黑色,将脊椎更改为白色(如图所示),但我希望更改平面的颜色(图像中的灰色区域)。我已经研究过了,但还没有找到办法。有什么方法可以改变3D matplotlib图形中平面的颜色吗?在


Tags: paramsaxlabelcolorwhitecolorssetaxis