python - specific location for inset axes -
i want create set of axes form inset @ specific location in parent set of axes. therefore not appropriate use parameter loc=1,2,3 in inset_axes shown here:
inset_axes = inset_axes(parent_axes, width="30%", # width = 30% of parent_bbox height=1., # height : 1 inch loc=3) however, close this. , answers here , here seem answers questions more complicated mine.
so, question is there parameter can replace in above code allow custom locations of inset axes within parent axes? i've tried use bbox_to_anchor not understand it's specification or behavior documentation. i've tried:
inset_axes = inset_axes(parent_axes, width="30%", # width = 30% of parent_bbox height=1., # height : 1 inch bbox_to_anchor=(0.4,0.1)) to try anchor left , bottom of inset @ 40% , 10% of x , y axis respectively. or, tried put in absolute coordinates:
inset_axes = inset_axes(parent_axes, width="30%", # width = 30% of parent_bbox height=1., # height : 1 inch bbox_to_anchor=(-4,-100)) neither of these worked correctly , gave me warning couldn't interpret.
more generally, seems loc pretty standard parameter in many functions belonging matplotlib, so, there general solution problem can used anywhere? seems that's bbox_to_anchor again, can't figure out how use correctly.
the approach took in principle correct. however, when placing legend bbox_to_anchor, location determined interplay between bbox_to_anchor , loc. of explanation in above linked answer applies here well.
the default loc inset_axes loc=1 ("upper right"). means if you specify bbox_to_anchor=(0.4,0.1), coordinates of upper right corner, not lower left one.
therefore need specify loc=3 have lower left corner of inset positionned @ (0.4,0.1). ideally, , according documentation, following should work
inset_axes = inset_axes(parent_axes, width="30%", height="70%", bbox_to_anchor=(0.4,0.1), loc=3) if wanted position inset in other coordinates default axes coodinates, need use bbox_transform argument, again, legends explained here.
however, either documentation wrong or there bug in current matplotlib version, such the above not work.
a workaround use insetposition instead of inset_axes , give existing axes new position. insetposition takes x , y coordinates of lower left corner of axes in normalized axes coordinates, width , height input.
import matplotlib.pyplot plt mpl_toolkits.axes_grid1.inset_locator import insetposition fig, ax= plt.subplots() iax = plt.axes([0, 0, 1, 1]) ip = insetposition(ax, [0.4, 0.1, 0.3, 0.7]) #posx, posy, width, height iax.set_axes_locator(ip) iax.plot([1,2,4]) plt.show()
Comments
Post a Comment