使用matplotlib绘制一些数据,插入ax.twiny()
模块会改变y轴的比例。
在我使用之前:
之后:
我想避免在y轴上手动插入限制。
那为什么会发生这种情况,以及如何解决它?
答案 0 :(得分:1)
这很奇怪。
我尝试过使用twiny()选项,它不会改变比例:
import numpy
import matplotlib.pylab as plt
x = numpy.linspace(0, 4. * numpy.pi, 1000)
y = numpy.cos(x)
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.plot(x, y)
ax2 = ax1.twiny()
这不包含ax2 = ax1.twiny()
:
和ax2 = ax1.twiny()
:
这也是你实现第二个x轴的方式吗?
使用ax2
,您将能够使用共享的y轴和第二个x轴绘制新数据。
希望这有帮助!
答案 1 :(得分:0)
我也有这个问题。不知道是什么原因造成的。这是一个更强大的修复程序
ax2.set_xlim(ax.get_xlim())