关闭子图中的轴
我有以下代码:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.cm as cm
img = mpimg.imread("lena.jpg")
fig, axs = plt.subplots(2, 2)
axs[0,0].imshow(img, cmap = cm.Greys_r)
axs[0,0].set_title("Rank = 512")
rank = 128
new_img = prune_matrix(rank, img)
axs[0,1].imshow(new_img, cmap = cm.Greys_r)
axs[0,1].set_title("Rank = %s" %rank)
rank = 32
new_img = prune_matrix(rank, img)
axs[1,0].imshow(new_img, cmap = cm.Greys_r)
axs[1,0].set_title("Rank = %s" %rank)
rank = 16
new_img = prune_matrix(rank, img)
axs[1,1].imshow(new_img, cmap = cm.Greys_r)
axs[1,1].set_title("Rank = %s" %rank)
plt.show()
但是,由于轴上的值,结果非常难看:
我怎样才能同时关闭所有子图的轴值?
如何删除轴、图例和白色填充不起作用,因为我不知道如何使它与次要情节。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Axes
off by following the advice in Veedrac's comment (linking toax
是matplotlib.axes
对象。axes
,axs [0,0] .axis('off'')
等等,等等。Pyplot
和axes
。之间的区别
prune_matrix
的结果,这是不可用的。注意:仅关闭X或Y轴,您可以使用
set_visible()
eg:Axes
off by following the advice in Veedrac's comment (linking to here) with one small modification.plt.axis('off')
, useax.axis('off')
whereax
is amatplotlib.axes
object.Axes
,axs[0, 0].axis('off')
, and so on for each subplot.pyplot
andAxes
.prune_matrix
, which is not available.Note: To turn off only the x or y axis you can use
set_visible()
e.g.:给定:
要关闭所有子图的轴:
Given:
To turn off axes for all subplots:
另一种可能的方法是在绘制每个轴时将它们的
axison
属性设置为 False。如果您想清楚地看到删除的内容,可以使用
Axes.set()
分别“删除”框架和刻度。最后,如果您想在绘制图形后删除框架和刻度,您可以循环遍历图形本身中的轴列表。
注意此处给出的所有三个方法(
axis('off')
、set_axis_off()
和axison=False
)都是等效的方法,因为在底层,axis('off')
调用set_axis_off()
,后者又执行axison=False
,因此最终它们是相同的。Another possible way is to set the
axison
attribute to False for each Axes as they get plotted.If you want to clearly see what is removed, you can "remove" frames and ticks separately using
Axes.set()
.Finally, if you want to remove the frames and ticks after the graphs are plotted, you can loop over the list of axes in the figure itself.
N.B. All three methods given here (
axis('off')
,set_axis_off()
andaxison=False
) are equivalent methods because under the hood,axis('off')
callsset_axis_off()
, which in turns doesaxison=False
, so ultimately, they are the same.