You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importmatplotlib.pyplotaspltimportnumpyasnp# To make things reproducible...np.random.seed(1977)
fig, ax=plt.subplots()
# Twin the x-axis twice to make independent y-axes.axes= [ax, ax.twinx(), ax.twinx()]
# Make some space on the right side for the extra y-axis.fig.subplots_adjust(right=0.75)
# Move the last y-axis spine over to the right by 20% of the width of the axesaxes[-1].spines['right'].set_position(('axes', 1.2))
# To make the border of the right-most axis visible, we need to turn the frame# on. This hides the other plots, however, so we need to turn its fill off.axes[-1].set_frame_on(True)
axes[-1].patch.set_visible(False)
# And finally we get to plot things...colors= ('Green', 'Red', 'Blue')
forax, colorinzip(axes, colors):
data=np.random.random(1) *np.random.random(10)
ax.plot(data, marker='o', linestyle='none', color=color)
ax.set_ylabel('%s Thing'%color, color=color)
ax.tick_params(axis='y', colors=color)
axes[0].set_xlabel('X-axis')
plt.show()
I think this is a duplicate of #51 -- eventually I want to support arbitrarily many "hanging" twins (or I guess triplets, quadruplets, ...) with the spines automatically spaced out from each other in an EdgeStack.
For now though I make twin[xy] enforce rigid formatting and automatically apply axis sharing. So until #51 is implemented I think I'm going to keep the <=2 twins restriction -- otherwise would have to temporarily rewrite a lot of the twin[xy] code.
...actually I changed my mind. Looked at it more closely and my alt[xy] restrictions really weren't necessary (think they originally had to do with making it easier to write the tight layout algorithm, but that algorithm has since been simplified).
It's now fixed -- you can add as many twin axes as you want, and I no longer force twin axes back into a rigid format at drawtime. Here is an adaptation of your example with proplot:
fig, ax=plot.subplots()
# Twin the x-axis twice to make independent y-axes.axs= [ax, ax.twinx(), ax.twinx()]
# Move the last y-axis spine over to the right by 20% of the width of the axesaxs[-1].spines['right'].set_position(('axes', 1.2))
# And finally we get to plot things...colors= ('Green', 'Red', 'Blue')
forax, colorinzip(axs, colors):
data=np.random.random(1) *np.random.random(10)
ax.plot(data, marker='o', linestyle='none', color=color)
ax.format(ylabel='%s Thing'%color, ycolor=color)
axs[0].format(xlabel='X-axis')
Activity
CatNofishing commentedon Sep 24, 2020
Thanks, this is a really powerful program. I love it. It is better than matplotlib.
lukelbd commentedon Jun 30, 2021
I think this is a duplicate of #51 -- eventually I want to support arbitrarily many "hanging" twins (or I guess triplets, quadruplets, ...) with the spines automatically spaced out from each other in an
EdgeStack.For now though I maketwin[xy]enforce rigid formatting and automatically apply axis sharing. So until #51 is implemented I think I'm going to keep the <=2 twins restriction -- otherwise would have to temporarily rewrite a lot of thetwin[xy]code.lukelbd commentedon Jun 30, 2021
...actually I changed my mind. Looked at it more closely and my
alt[xy]restrictions really weren't necessary (think they originally had to do with making it easier to write the tight layout algorithm, but that algorithm has since been simplified).It's now fixed -- you can add as many twin axes as you want, and I no longer force twin axes back into a rigid format at drawtime. Here is an adaptation of your example with proplot: