python - How can I use matplotlib divider to split a subplot into more than two parts? -
i've generated image containing 4 subplots (globe, indian, pacific , atlantic) using gridspec:
matplotlib import gridspec fig = plt.figure() gs = gridspec.gridspec(2, 2) each of subplots uses divider can use different vertical scale shallow , deep ocean:
mpl_toolkits.axes_grid1 import make_axes_locatable axmain = plt.subplot(gs[0]) plt.sca(axmain) cf = axmain.contourf(...) divider = make_axes_locatable(axmain) axshallow = divider.append_axes("top", size="100%", pad=0.1, sharex=axmain) axshallow.contourf(...) i want add line graph top of each subplot (i.e. third plot on top of other two), showing integrated value each latitude on entire 2000m depth of plot (i.e. third plot share x-axis of other 2 below it).
i can't figure out how divide each subplot third time, hoping suggest how might this?
dividing axes several times using make_axes_locatable possible. need call divider.append_axes(..) second (or third etc.) time.
here example.
import numpy np import matplotlib.pyplot plt matplotlib import gridspec mpl_toolkits.axes_grid1 import make_axes_locatable fig = plt.figure() gs = gridspec.gridspec(2, 2) x, y = np.meshgrid(np.linspace(0,100, num=101), np.linspace(0,100, num=101)) f = lambda x, y: np.sin(x/10.)+y/100. axmain = plt.subplot(gs[0]) plt.sca(axmain) cf = axmain.contourf(x[0:40,:], y[0:40,:], f(x,y)[0:40,:] , vmin=-1, vmax=2) divider = make_axes_locatable(axmain) axshallow = divider.append_axes("top", size="100%", pad=0.1, sharex=axmain) axshallow.contourf(x[41:80,:], y[41:80,:], f(x,y)[41:80,:], vmin=-1, vmax=2) axshallow.set_xticklabels([]) axshallow2 = divider.append_axes("top", size="50%", pad=0.1, sharex=axmain) axshallow2.contourf(x[81:,:], y[81:,:], f(x,y)[81:,:], vmin=-1, vmax=2) axshallow2.set_xticklabels([]) plt.show() 
Comments
Post a Comment