3D绘图Matplotlib中文本的部分着色

时间:2016-02-26 08:17:10

标签: python matplotlib

是否可以更改3D绘图中文本的颜色。我的问题类似于这个问题Partial coloring of text in matplotlib,但我没有使用2D绘图而是使用3D绘图。

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import transforms

fig = plt.figure()
ax = Axes3D(fig)
x =1
y =2
z =3
ax.set_xlim3d(0,5)
ax.set_ylim3d(0,5)
ax.set_zlim3d(0,5)
ax.set_xticks(range(5))
ax.set_yticks(range(5))
ax.set_zticks(range(5))

t=ax.transData

ax.scatter([x], [y], [z], c='r', marker='*', s=500)

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

ls="Data Point".split()

lc=['red','orange']
x=0.5
y=0.5
z=0.5


for s,c in zip(ls,lc):
        try:
            text = ax.text(x,y,z," "+s+" ",color=c, transform=t,size=50)
            text.draw(fig.canvas.get_renderer())
            ex = text.get_window_extent()
            t = transforms.offset_copy(text._transform, y=ex.height,x=ex.width, units='dots')

        except:
            print "error"



plt.show()

0 个答案:

没有答案