i have plot y axis devided 2 parts. lower part should have normal scale while upper 1 should scale factor of 10.
i found examples on how make plots broken x or y axes, example: http://matplotlib.org/examples/pylab_examples/broken_axis.html
but not understand how achieve this, when want apply 1 single subplot inside 2x2 grid of plots. if important, set plots this:
fig = plt.figure() fig.set_size_inches(8, 6) fig.add_subplot(221) [...] fig.add_subplot(222) [...]
you use gridspec layout shape , location of axes:
import numpy np import matplotlib.gridspec gridspec import matplotlib.pyplot plt gs = gridspec.gridspec(4, 2) ax00 = plt.subplot(gs[:2, 0]) ax01 = plt.subplot(gs[:2, 1]) ax10a = plt.subplot(gs[2, 0]) ax10b = plt.subplot(gs[3, 0]) ax11 = plt.subplot(gs[2:, 1]) x = np.linspace(-1, 1, 500) y = 100*np.cos(10*x)**2*np.exp(-x**2) ax in (ax00, ax01, ax10a, ax10b, ax11): ax.plot(x, y) ax10a.set_ylim(60, 110) ax10b.set_ylim(0, 10) ax10a.spines['bottom'].set_visible(false) ax10b.spines['top'].set_visible(false) ax10a.xaxis.tick_top() ax10a.tick_params(labeltop='off') # don't put tick labels @ top ax10b.xaxis.tick_bottom() d = .015 # how big make diagonal lines in axes coordinates # arguments pass plot, don't keep repeating them kwargs = dict(transform=ax10a.transaxes, color='k', clip_on=false) ax10a.plot((-d,+d),(-d,+d), **kwargs) # top-left diagonal ax10a.plot((1-d,1+d),(-d,+d), **kwargs) # top-right diagonal kwargs.update(transform=ax10b.transaxes) # switch bottom axes ax10b.plot((-d,+d),(1-d,1+d), **kwargs) # bottom-left diagonal ax10b.plot((1-d,1+d),(1-d,1+d), **kwargs) # bottom-right diagonal plt.tight_layout() plt.show() 
Comments
Post a Comment