Matplotlib:无法同时关闭轴和设置面色吗? [英] Matplotlib: Turning axes off and setting facecolor at the same time not possible?
本文介绍了Matplotlib:无法同时关闭轴和设置面色吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以解释为什么在关闭轴的情况下,这个简单的代码不会执行facecolor命令吗?
can someone explain why this simple code wont execute the facecolor command while setting the axis off?
fig = plt.figure(1)
ax = fig.add_subplot(211, facecolor=(0,0,0), aspect='equal')
ax.scatter(np.random.random(10000), np.random.random(10000), c="gray", s=0.25)
ax.axes.set_axis_off()
提前致谢!
推荐答案
背景补丁是轴的一部分.因此,如果轴已关闭,则背景色块也将关闭.
The background patch is part of the axes. So if the axes is turned off, so will the background patch.
一些选项:
ax = fig.add_subplot(211, facecolor=(0,0,0), aspect='equal')
ax.set_axis_off()
ax.add_artist(ax.patch)
ax.patch.set_zorder(-1)
创建新补丁
ax = fig.add_subplot(211, facecolor=(0,0,0), aspect='equal')
ax.set_axis_off()
ax.add_patch(plt.Rectangle((0,0), 1, 1, facecolor=(0,0,0),
transform=ax.transAxes, zorder=-1))
使轴脊和刻度不可见
...但保持轴打开.
Turn axis spines and ticks invisible
...but keep the axis on.
ax = fig.add_subplot(211, facecolor=(0,0,0), aspect='equal')
for spine in ax.spines.values():
spine.set_visible(False)
ax.tick_params(bottom=False, labelbottom=False,
left=False, labelleft=False)
这篇关于Matplotlib:无法同时关闭轴和设置面色吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文