我使用现有的脚本来绘制一个非常特定的数据类型。该脚本返回一个ax对象。这些ax对象用于填充新的更大主图中的子图。
在主脚本中的某处,
ax.set_yticks([])是调用的。通常这是想要的。对于其中一个单独的绘图脚本,我想简单地撤销这一点,并让matplotlib根据数据自动设置y滴答,就像从未调用过ax.set_yticks([])一样。
发布于 2017-07-06 22:02:53
您可以在调用set_yticks([])之前存储刻度定位器,并在以后恢复它
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()https://stackoverflow.com/questions/44949072
复制相似问题