无法从pyplot子批中删除yticks

2024-04-18 20:29:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我用matplotlib.pyplot. 即使我使用以下方法将记号标签设置为空:

plt.xticks([ ])
plt.yticks([ ])

我怎样才能去掉这些?我是Python新手,如果有任何帮助,我将不胜感激。在

Plot


Tags: 方法matplotlibplt标签pyplot新手xticks记号
2条回答

您可以使用plt.tick_params选项微调绘图:

plt.tick_params(axis='both', which='both', right=False, left=False, top=False, bottom=False)

你的图中有很多子图。您需要删除每个子批次的每个轴对象中的记号(或者至少要删除要显示的标记)。可以这样做:

import matplotlib.pyplot as plt

ax1 = plt.subplot(321)  # 1st subplot in 3-by-2 grid
ax1.plot(...)  # draw what you want
ax1.set_xticks([], [])  # note you need two lists one for the positions and one for the labels
ax1.set_yticks([], [])  # same for y ticks

ax2 = plt.subplot(321)  # 2nd subplot in the same grid
# do the same thing for any subplot you want the ticks removed

如果要删除整个轴(边框、记号和标签),只需执行以下操作:

^{pr2}$

不过,我建议键入plt.tight_layout()。它可以解决您的问题,而不需要您删除勾号。在

相关问题 更多 >