首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >删除gridspec matlibplot图的xticks和yticks

删除gridspec matlibplot图的xticks和yticks
EN

Stack Overflow用户
提问于 2020-03-11 11:45:18
回答 1查看 667关注 0票数 2

我正在尝试从我设置的网格规范图中删除所有标签和x/ytick。

下图是我当前的输出,但我需要删除所有的标签和x-tick和y-ticks,这样它们基本上就是空框。因为某些原因,我就是做不到。

这就是我正在使用的代码。

代码语言:javascript
复制
fig = plt.figure()
gs = fig.add_gridspec(2, 9)

# Query image
ax1 = fig.add_subplot(gs[:, 0])
#Positive image
ax2 = fig.add_subplot(gs[0, 1])
ax3 = fig.add_subplot(gs[0, 2])
ax4 = fig.add_subplot(gs[0, 3])
ax5 = fig.add_subplot(gs[0, 4])
# Negative images
ax6 = fig.add_subplot(gs[1, 1])
ax7 = fig.add_subplot(gs[1, 2])
ax8 = fig.add_subplot(gs[1, 3])
ax9 = fig.add_subplot(gs[1, 4])

# all_axes = fig.get_axes()
# # show only the outside spines
# for ax in all_axes:
#     for sp in ax.spines.values():
#         sp.set_visible(False)
#     if ax.is_first_row():
#         ax.spines['top'].set_visible(True)
#     if ax.is_last_row():
#         ax.spines['bottom'].set_visible(True)
#     if ax.is_first_col():
#         ax.spines['left'].set_visible(True)
#     if ax.is_last_col():
#         ax.spines['right'].set_visible(True)
plt.tick_params(axis='x',
           which='both',
           bottom=False,
           top = False,
           labelbottom=False)
#plt.axis('off')
#plt.xticks([], [])
#plt.xticks.remove
#plt.yticks.remove
plt.show()

我已经尝试了几种方法,但仍然不好。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-11 12:40:26

您应该使用matplotlib.axes.Axes.tick_params()而不是matplotlib.pyplot.tick_params()。后者将仅应用于“当前”,在本例中是最近创建的axes实例-前者允许您将tick参数应用于任何axes实例。考虑一下:

代码语言:javascript
复制
for ax in fig.get_axes():
    ax.tick_params(bottom=False, labelbottom=False, left=False, labelleft=False)

这将产生

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60628986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档