是否有可能在pylab中将图形的一部分变为白色?

时间:2014-12-03 16:36:07

标签: python numpy matplotlib matplotlib-basemap

我正在尝试使用pylabPIL.ImageFontPIL.ImagePIL.ImageDraw numpy以及其他几个来制作3D验证码。在大多数情况下,它似乎工作。例如:
http://puu.sh/dft1a/1d35f5c99a.png
http://puu.sh/dfuat/f35fa6d155.jpg

我希望能够做的是让z = 0为白色,即删除不属于文本的颜色。这可能吗?

我尝试过设置Axes3D.plot_surface(alpha = .2,linewidth = 0),结果如下:
http://puu.sh/dfupq/223ad49403.jpg

虽然这比我想要的更接近,但我想删除一般的背景颜色,只留下文字颜色

这是创建3D文本的主要部分:

draw = ImageDraw.Draw(img)
draw.text((text_width, text_height), text, font=font)

fig = pylab.figure(figsize=(width/100.0, height/100.0), dpi=4000)
axes = Axes3D(fig)
X, Y = numpy.meshgrid(range(img.size[0]), range(img.size[1]))
Z = 1 - numpy.asarray(img) / 255 if not hard else 50

if hard:
    func = Axes3D.plot_wireframe
else:
    func = Axes3D.plot_surface if random.randint(0,1) == 0 else Axes3D.plot_wireframe

func(axes, X, -Y, Z, rstride=1, cstride=1, color=_rand_color())

axes.set_zlim((-3, 3))
axes.set_xlim((text_width * 1.1, text_width * 1.9))
axes.set_ylim((-text_height * 1.9, -text_height* 1.1))
axes.set_axis_off()
axes.view_init(elev=60, azim=-90+angle)

如果有人有任何想法,我们将不胜感激!

0 个答案:

没有答案