在一个implot(matplotlib)上以相同的比例绘制两个y轴

时间:2016-07-13 14:30:39

标签: python matplotlib plot

我有一个图像图,表示一个矩阵,有两个轴。我的图像绘图左侧的y轴表示行,x轴表示列,而每个网格单元表示作为x和y的函数的值。

我想在我的图像绘图的右侧以另一种形式绘制我的y轴,它采用更小的值,但仍应与左侧的y轴位于相同的位置,如价值观是彼此不同的形式。问题是,当我使用fig.twinx()并去绘制y轴时,它甚至都没有显示出来!有谁知道锣上有什么?感谢。

当前代码:

# Setup the figure
fig5 = pyplot.figure(5, figsize=(10,9), facecolor='white')
pyplot.gcf().clear()
# plt.rc('xtick', labelsize=20)
# plt.rc('ytick', labelsize=20)
plt.rcParams.update({'font.size': 18})
fig5ax = pyplot.axes()

# Code to calculate extent based on min/max range and my x values

implot = pyplot.imshow(valgrid, extent=MyExtent , aspect='auto', vmin = myVmin, vmax = myVmax) 

fig5ax.yaxis.set_major_formatter(plt.ticker.FixedFormatter([str(x) for x in ranges]))
fig5ax.yaxis.set_major_locator(plt.ticker.FixedLocator(ranges))

fig5Ax2 = fig5ax.twinx()
fig5Ax2.yaxis.set_major_formatter(plt.ticker.FixedFormatter([str(x) for x in time]))
# Setting locater the same as ranges, because I want them to line up
# as they are different forms of the same y value
fig5Ax2.yaxis.set_major_locator(plt.ticker.FixedLocator(ranges))

pyplot.show()

1 个答案:

答案 0 :(得分:1)

答案是:

fig5Ax2.yaxis.set_view_interval(minRange, maxRange)