Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed as not planned
Description
I am reporting as possible bug.
When plotting a secondary y axis on the right, the xlim is not being properly auto scaled. As possible work around was proposed here,https://stackoverflow.com/a/27344398/4988010, however, it seems this was fixed here,26ed35b. However, I am not seeing the issue being resolved on matplotlib v3.2.0.
%matplotlibwidgetimportmatplotlib.pyplotaspltimportnumpyasnpfig,ax=plt.subplots()decay=lambdaC,K,x:C*(1-np.exp(-1*K*x))x=np.linspace(0,10,10)# Create a secondary y axis on the righttwin_ax=ax.twinx()forninrange(5):C=n**2+5K=0.75# Plot the exponential decay on left y axisax.plot(x,decay(C,K,x),marker='o',linestyle='--',label=C)# Plot the limit of decay on right y axistwin_ax.axhline(y=C,color='gray')ax.legend()ax.set_xlabel('X')ax.set_ylabel('Measured values')twin_ax.set_ylabel('Theoritical limit')# Align the both left and right y axistwin_ax.set_ylim(ax.get_ylim())################### Issues or bugs# Need to fix the X limits or else# the graph doens't display properly##################print('xlim before fix: {}'.format(ax.get_xlim()))ax.relim()print('xlim after relim(): {}'.format(ax.get_xlim()))# A hack to fix the issue # https://stackoverflow.com/a/27344398/4988010twin_ax.plot(0,0,visible=False)print('xlim after fixing: {}'.format(ax.get_xlim()))plt.show()