【发布时间】:2020-11-24 14:47:13
【问题描述】:
我有一个 Matplotlib 图,其中有 6 个相邻的垂直图,所有图都具有 sharey=True。当我在任何一个绘图上移动光标时,我希望在另一个 5 上显示一个水平光标/标记。我了解 MultiCursor 是最好的方法。我看过这个,当我运行它时它可以正常工作,无论是在水平图上。我的代码没有在任何 GUI 中运行(如果有区别的话),但这个演示也不是。 Matplotlib gallery demo
当我尝试使用我的情节时,没有任何反应。下面的绘图代码仅链接两个子图而不是全部 6 个,但它无论如何都不起作用。我在代码主体中导入了 MultiCursor。
def Raw_Plot(): #Raw Data Plot
global unitW
fig, axs=plt.subplots(1,6,constrained_layout=True, sharey=True)
fig.suptitle(tail)
axs[0].plot(df['Cone'],df['Depth'],'r-',linewidth=0.8)
axs[0].set_xlabel('$q_c$ (MPa)')
axs[0].set_ylabel('Depth (m)')
axs[0].set_title('Cone resistance',fontsize=10)
axs[0].grid()
axs[0].set_ylim(dmax,0)
axs[0].set_xlim(0,None)
axs[1].plot(df['Friction'],df['Depth'],'b-',linewidth=0.8)
axs[1].set_xlabel('$f_s$ (MPa)')
axs[1].set_title('Sleeve Friction',fontsize=10)
axs[1].grid()
axs[1].set_xlim(0,None)
axs[1].set_ylabel('Depth (m)')
axs[2].plot(df['Pore'],df['Depth'],'g-',linewidth=0.8)
axs[2].plot(df['AmbientM'],df['Depth'],'r-',linewidth=0.8)
axs[2].plot(df['Bq'],df['Depth'],'g--',linewidth=0.8)
axs[2].set_xlabel('$U_2$, $U_0$ (MPa) & $B_q$')
axs[2].set_title('Raw, Ambient and \n Normalised Pore Pressures',fontsize=10)
axs[2].grid()
axs[2].set_ylabel('Depth (m)')
axs[3].plot(df['Rf'],df['Depth'],'c-',linewidth=0.8,label='$R_f$')
axs[3].plot(df['Fr'],df['Depth'],'b-',linewidth=0.8, label='$F_r$')
axs[3].set_xlabel('$F_r$ & $R_f$ (%)')
axs[3].set_xlim(0,10)
axs[3].set_title('Friction Ratios',fontsize=10)
axs[3].set_ylabel('Depth (m)',fontsize=10)
axs[3].legend(loc='upper right',bbox_to_anchor=(1,1),fontsize=6.5)
axs[3].grid()
axs[4].plot(df['Qtn'],df['Depth'],'r-',linewidth=0.8)
axs[4].set_xlabel('$Q_{tn}$')
axs[4].set_ylabel('Depth (m)')
axs[4].set_title('Normalised Cone resistance',fontsize=10)
axs[4].grid()
axs[4].set_ylim(dmax,0)
axs[4].set_xlim(0,None)
axs[5].plot(df['GammaS'],df['Depth'],'c-',linewidth=0.8, label='Calculated')
axs[5].plot(df['GaDef'],df['Depth'],'b-',linewidth=1.0, label='Default '+str(unitW))
axs[5].legend(loc='upper right',bbox_to_anchor=(1,1),fontsize=6.5)
axs[5].set_xlabel('$\gamma$ $(kN/m^3)$')
axs[5].set_xlim(14,20)
axs[5].xaxis.set_major_formatter(FormatStrFormatter('%.1f'))
axs[5].set_title('Soil Unit Weight',fontsize=10)
axs[5].set_ylabel('Depth (m)')
axs[5].grid()
fig.canvas.set_window_title(tail)
multi=MultiCursor(fig.canvas,(axs[1],axs[4]),color='r',lw=1)
plt.ion() #makes plot non-blocking - Can open multiple plots
plt.show()
【问题讨论】:
标签: python-3.x macos matplotlib matplotlib-widget