matplotlib同x轴作图,y轴反转

matplotlib同x轴作图,y轴反转
编辑删除转载2018-10-08 15:08:09
标签:linux
stackoverflow.com/questions/37737538/merge-matplotlib-subplots-with-shared-x-axis 

这里给了个例子,用了gridspec,其实只用subplot就可以了。


ax1=plt.subplot(211)

plt.vlines(tm1,0,mg1,color='r')

plt.xlim((1700,2020))

plt.ylim((0,8))

plt.setp(ax1.get_xticklabels(),visible=False)  ###隐藏第一个图的x轴标注



ax2=plt.subplot(212,sharex=ax1)

plt.vlines(tm2,0,mg2,color='b')

plt.xlim((1700,2020))

plt.ylim((8,0))   ##### 这里反着写,让y轴倒过来

yticks=ax2.yaxis.get_major_ticks()

yticks[0].label1.set_visible(False)  #### 两个图相交的y轴第一个标注会重叠,让第二个坐标的标注隐藏

plt.subplots_adjust(hspace=.0)    ##### 让两个图的间隔为0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注