python - custom axes layout using axis_grid toolkit -
i have issue make_axes_locatable/append_axes in axis_grid toolkit, when function calls nested, e.g.,
divider1 = make_axes_locatable(ax1) divider2 = make_axes_locatable(divider1.append_axes(...)) if utilize above code create 3 axes in (4,5,6), main axis (ax4) hidden behind other 2 on right (see figure below , this gist). guess make_axes_locatable/append_axes not meant used way.
all want place colorbar not @ top of ax1 (like in figure below - this gist) in empty space below table. advantage of make_axes_locatable figure still looks if resize it, in contrast manually creating axis objects using fig.add_axes() (code @ end of 4).
can tell me how split right axis (ax2) s.t. space below table used colorbar , ticklabels?
i'm not sure can axesdivider.append_axes since according documentation method "create[s] axes @ given position same height (or width) of main axes." want axes on right have different heights 1 on left.
another alternative create 2 subplots , utilize divider break subplots on right:
import matplotlib.pyplot plt mpl_toolkits.axes_grid1 import make_axes_locatable ax = plt.subplot(121) ax2 = plt.subplot(122) divider = make_axes_locatable(ax2) ax3 = divider.append_axes("bottom", size="50%", pad=0.5) plt.show() or create divider straight (without using makes_axes_locatable) shown here , below:
import matplotlib.pyplot plt mpl_toolkits.axes_grid import divider import mpl_toolkits.axes_grid.axes_size size fig1 = plt.figure(1, (5.5, 4.)) # rect parameter ignore set axes_locator rect = (0.1, 0.1, 0.8, 0.8) ax = [fig1.add_axes(rect, label="%d"%i) in range(3)] horiz = [size.scaled(1.5), size.fixed(.5), size.scaled(1.), size.scaled(.5)] vert = [size.scaled(1.), size.fixed(.5), size.scaled(1.5)] # split axes rectangle grid size specified horiz * vert divider = divider(fig1, rect, horiz, vert, aspect=false) ax[0].set_axes_locator(divider.new_locator(nx=0, ny=0, ny1=3)) ax[1].set_axes_locator(divider.new_locator(nx=2, ny=2)) ax[2].set_axes_locator(divider.new_locator(nx=2, ny=0)) plt.show() or if there no reason utilize divider @ all, utilize gridspec:
import matplotlib.pyplot plt ax1 = plt.subplot2grid((2,2), (0,0), rowspan=2) ax2 = plt.subplot2grid((2,2), (0, 1)) ax3 = plt.subplot2grid((2,2), (1, 1)) plt.show() all 3 of options create looks this:
all 3 of these looked ok when resized them, @ to the lowest degree simple example.
edit can utilize gridspec , subplotto axes on left aspect ratio of 1 , pair of axes on right line top , bottom of left axes. trick set aspect ration of gridspec using width_ratios , height_ratios. when figure resized top , bottom of right axes still line top , bottom of left axes.
import matplotlib.pyplot plt import matplotlib.gridspec gridspec fig = plt.figure() # grid spec left , right columns gs0 = gridspec.gridspec(1, 2,width_ratios=[1,1], height_ratios=[1,1]) # gird spec left axes aspect ratio of 1 gs00 = gridspec.gridspecfromsubplotspec(1, 1, subplot_spec=gs0[0], width_ratios=[1], height_ratios=[1]) ax1 = plt.subplot(fig, gs00[0]) fig.add_subplot(ax1) # grid spec 2 right axes gs01 = gridspec.gridspecfromsubplotspec(2, 1, subplot_spec=gs0[1]) ax2 = plt.subplot(fig, gs01[0]) ax3 = plt.subplot(fig, gs01[1]) fig.add_subplot(ax2) fig.add_subplot(ax3) plt.show() python matplotlib
No comments:
Post a Comment