撤消斧头套件([])

2024-10-06 13:24:01 发布

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

我使用现有的脚本来绘制非常特定的数据类型。脚本返回一个ax对象。 这些ax对象用于填充新的更大的主图中的子图。在

在主脚本的某个地方

ax.set_yticks([])

被称为。通常这是需要的。对于其中一个单独的绘图脚本,我只想撤销这个操作,让matplotlib根据数据自动设置y记号,就像从未调用过ax.set_yticks([])。在


Tags: 数据对象脚本绘图matplotlib地方绘制ax
1条回答
网友
1楼 · 发布于 2024-10-06 13:24:01

您可以在调用set_yticks([])之前存储tick定位器,并在以后恢复它

import matplotlib.pyplot as plt

ax = plt.gca()
ax.plot(range(10), range(10), 'ko')

#store the yticks locator
l = ax.yaxis.get_major_locator()


#hide ticks and display the figure
ax.set_yticks([])
plt.gcf().show()
raw_input('pause') # => no more yticks

#restore the tick locator to its originale state
ax.yaxis.set_major_locator(l)
plt.gcf().canvas.draw()  #refresh the plot to sow the yticks again

plt.show()

相关问题 更多 >