[英]Python Pylab - set 3d text color
I have a 3d plot in Python Pylab:我在 Python Pylab 中有一个 3d plot:
import numpy
import pylab
from PIL import Image, ImageDraw, ImageFont
import mpl_toolkits.mplot3d.axes3d as axes3d
img = Image.new('L', (60, 40), 255)
drw = ImageDraw.Draw(img)
font = ImageFont.truetype('arial.ttf', 20)
drw.text((5, 1), 'TEXT', font = font)
X, Y = numpy.meshgrid(range(60), range(40))
Z = 1 - numpy.asarray(img) / 255
fig = pylab.figure()
ax = axes3d.Axes3D(fig)
ax.plot_surface(X, -Y, Z, rstride = 1, cstride = 1)
ax.set_zlim((0, 50))
fig.show()
How can I make the text (and only the text, not the entire graph) a particular color?如何使文本(仅文本,而不是整个图形)具有特定颜色?
I've tried using the fill
and stroke_fill
arguments but they don't seem to do anything.我试过使用fill
和描边填充stroke_fill
但它们似乎没有做任何事情。 Any suggestions?有什么建议么?
You can use a predefined colormap ( viridis
in this example) with the plot_surface
command.您可以在plot_surface
命令中使用预定义的颜色图(在本例中为viridis
)。
ax.plot_surface(X, -Y, Z, rstride = 1, cstride = 1, cmap='viridis')
Or, alternatively, you can create your own colormap
adjusting the vmax
parameter and the length of the colormap to achieve the desired output.或者,您也可以创建自己的colormap
图,调整vmax
参数和颜色图的长度,以实现所需的 output。
...
...
import mpl_toolkits.mplot3d.axes3d as axes3d
from matplotlib.colors import ListedColormap
colors=["gray", "black"]
cmap = ListedColormap(colors)
img = Image.new('L', (60, 40), 255)
...
ax.plot_surface(X, -Y, Z, rstride = 1, cstride = 1, cmap=cmap, vmin=0, vmax=0.1)
...
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.