Matplotlib: Turning axes off and setting facecolor at the same time not possible?

前提是你 提交于 2021-02-05 08:13:27

问题


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()

Thanks in advance!


回答1:


The background patch is part of the axes. So if the axes is turned off, so will the background patch.

Some options:

Re-add 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)

Create new patch

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)


来源:https://stackoverflow.com/questions/60805253/matplotlib-turning-axes-off-and-setting-facecolor-at-the-same-time-not-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!