我正在尝试从我设置的网格规范图中删除所有标签和x/ytick。
下图是我当前的输出,但我需要删除所有的标签和x-tick和y-ticks,这样它们基本上就是空框。因为某些原因,我就是做不到。

这就是我正在使用的代码。
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()我已经尝试了几种方法,但仍然不好。
发布于 2020-03-11 12:40:26
您应该使用matplotlib.axes.Axes.tick_params()而不是matplotlib.pyplot.tick_params()。后者将仅应用于“当前”,在本例中是最近创建的axes实例-前者允许您将tick参数应用于任何axes实例。考虑一下:
for ax in fig.get_axes():
ax.tick_params(bottom=False, labelbottom=False, left=False, labelleft=False)这将产生

https://stackoverflow.com/questions/60628986
复制相似问题