From: Jae-Joon Lee <lee.joon@gm...> - 2010-03-04 19:45:32
With axes aspect_ratio set, the position of the axes is determined
during the drawing time. And the position of the inset axes also need
to be adjusted during the drawing time to incorporate this,
One way to archive this is to set axes_locator attribute, which accept
a callable object that returns the position of the axes.
Here is a slightly modified version of your add_inset.
# Define a composite transform to go from data space in the Axes
# instance to figure coordinates.
# We need to perform a composite transform to get the location:
# data to display followed by display to figure (because axes())
# takes a rect for positions relative to the figure
def my_axes_locator(axes, renderer):
compTrans = ax.transData + ax.get_figure().transFigure.inverted()
x,y = compTrans.transform(ij)
bbox = [x-width/2.,y-height/2.,width,height]
# Place a subplot centered on the specified location with a fixed size
# (relative to the size of the figure)
# The green dot we plot here should cover up the red dot on the plot
# underneath this one. We have a problem if they don't align.
ax2 = plt.axes([0,0,1,1],axisbg='none', axes_locator=my_axes_locator)
On Thu, Mar 4, 2010 at 12:53 PM, Mike Kay <vdotdel@...> wrote:
> Hi list -
> I've got a need to add several axes instances (e.g., barplots) to an
> existing figure. These additional axes need to be placed relative to data
> points on that plot.
> A problem occurs if the aspect ratio of the parent axes is set to a fixed
> value rather than using 'auto'.
> The attached script illustrates the problem with a pair of plots. Both plot
> a single red dot on the parent figure. A subplot is then placed directly on
> top of this point and a single point is plotted there, in green. If all's
> well you shouldn't see the red dot and should just see the green dot. In
> figure 2, where the aspect ratio is fixed, the subplot does not get placed
> at the correct location.
> Have I stumbled onto a subtlety of transforms that I'm not accounting for or
> is this perhaps a bug?
> matplotlib version 0.99.1 on linux; numpy 1.2.1
> thanks a lot,
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> Matplotlib-users mailing list