zoomed in detail box

Hi everyone!

I’m also trying to do a detailed zoomed area of my plot, but I can’t manage to put the box in the position I want, bbox_to_anchor didn’t work in my case:

axins = zoomed_inset_axes(ax,3,loc=2,bbox_to_anchor=(0,0,0.5,0.5),bbox_transform=ax.transAxes)

This bbox_to_anchor tuple is just an example. I only want to move the zoomed box a little to the right, since the ticklabels overlap.

Any idea?

I really appreciate your help!

2009/7/10 Jae-Joon Lee <lee.j.joon@…287…>

···

---------- Forwarded message ----------
From: darkside <in.the.darkside@…287…>

Date: 2012/8/2
Subject: Re: [Matplotlib-users] zoomed in detail box
To: Jae-Joon Lee <lee.j.joon@…2015…87…>

On Thu, Jul 9, 2009 at 7:24 AM, Robin<robince@…287…> wrote:

On Wed, Jul 8, 2009 at 10:57 PM, Jae-Joon Lee<lee.j.joon@…287…> wrote:

If you use the svn version of matplotlib, you may use axes_grid toolkit.

http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html#insetlocator

Wow - this is really amazing. Sometimes it can be a bit frustrating

when I’m working to a deadline to figure out the details of Bbox’s and

such but when I find something like this it really makes it worth

while! It does exactly what I want, really easy to use and only took

about 5 lines! (It would be nice if there were some docstrings in

there though :))

On Thu, Jul 9, 2009 at 4:02 AM, Jae-Joon Lee<lee.j.joon@…287…> wrote:

However, It is possible to specify the location of the axes in

normalized axes coordinate.

http://thread.gmane.org/gmane.comp.python.matplotlib.general/16373

I’m afraid I didn’t really understand how to apply this in my case…

I guess I would have to set the position and everything by hand

instead of using the zoom helper. I preferred to use the zoom helper,

but found the legend loc settings put it slightly too close to the

edge of the surrounding axes for my taste.

So after checking the docstrings for how to position legends I came up

with something that works, but it required a minor change to the

inset_locator.py to pass the bbox_to_anchor and bbox_transform (it

looks like this was intended since they have None default values):

robin-mbp-3:~ robince$ diff

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/mpl_toolkits/axes_grid/inset_locator.py

code/scipy_build/matplotlib/lib/mpl_toolkits/axes_grid/inset_locator.py

288c288

< axes_locator = AnchoredZoomLocator(parent_axes, zoom=zoom,

loc=loc, bbox_to_anchor=bbox_to_anchor,bbox_transform=bbox_transform)


axes_locator = AnchoredZoomLocator(parent_axes, zoom=zoom, loc=loc)

With this minor change I get exactly what I want!

Thanks for the catch. I’ll commit the change to the svn soon.

By the way, borderpad keyword is meant to do what you want. However, I

just found that it does not work sine the option is not properly

handled. I’ll fix this in the next commit.

Regards,

-JJ

ax1ins = zoomed_inset_axes(ax1, 3,

bbox_to_anchor=(0.1,0,1,1),bbox_transform=ax1.transAxes, loc=6)

plot_trial_dists(res515[0],8,ax=ax1ins)

ax1ins.set_xlim([5, 50])

ax1ins.set_ylim([0, 0.04])

ax1ins.set_xticks([])

ax1ins.set_yticks([])

mark_inset(ax1, ax1ins, loc1=2, loc2=4, fc=“none”, ec=“0.5”)

thanks again, this is really terrific!

Cheers

Robin


Enter the BlackBerry Developer Challenge

This is your chance to win up to $100,000 in prizes! For a limited time,

vendors submitting new applications to BlackBerry App World™ will have

the opportunity to enter the BlackBerry Developer Challenge. See full prize

details at: http://p.sf.net/sfu/Challenge


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Is this what you are looking for?

http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html#insetlocator

Cheers!
Ben Root

···

On Wed, Aug 8, 2012 at 7:03 AM, darkside <in.the.darkside@…287…> wrote:

---------- Forwarded message ----------
From: darkside <in.the.darkside@…287…>

Date: 2012/8/2
Subject: Re: [Matplotlib-users] zoomed in detail box
To: Jae-Joon Lee <lee.j.joon@…287…>

Hi everyone!

I’m also trying to do a detailed zoomed area of my plot, but I can’t manage to put the box in the position I want, bbox_to_anchor didn’t work in my case:

axins = zoomed_inset_axes(ax,3,loc=2,bbox_to_anchor=(0,0,0.5,0.5),bbox_transform=ax.transAxes)

This bbox_to_anchor tuple is just an example. I only want to move the zoomed box a little to the right, since the ticklabels overlap.

Any idea?

I really appreciate your help!

Thank you for your help, but I have already read this link.

I am using zoomed_inset_axes, but the default position overlaps the yticks and the parent axe ticks, so I am trying:
axins = zoomed_inset_axes(ax, 3,bbox_to_anchor(0.5,1),bbox_transform=ax.figure.transFigure, loc=2)

but it doesn’t work.
I have also tried:
box = axins.get_position()
axins.set_position([box.x0+0.5, box.y0,box.width, box.height])

and the position is changed (doing a print I check the differences), but not in the plot.

I guess I am doing something wrong, but I can’t tell.

Any help would be really useful.

Cheers!
Illa

2012/8/9 Benjamin Root <ben.root@…1304…>

···

On Wed, Aug 8, 2012 at 7:03 AM, darkside <in.the.darkside@…287…> wrote:

---------- Forwarded message ----------
From: darkside <in.the.darkside@…287…>

Date: 2012/8/2
Subject: Re: [Matplotlib-users] zoomed in detail box
To: Jae-Joon Lee <lee.j.joon@…287…>

Hi everyone!

I’m also trying to do a detailed zoomed area of my plot, but I can’t manage to put the box in the position I want, bbox_to_anchor didn’t work in my case:

axins = zoomed_inset_axes(ax,3,loc=2,bbox_to_anchor=(0,0,0.5,0.5),bbox_transform=ax.transAxes)

This bbox_to_anchor tuple is just an example. I only want to move the zoomed box a little to the right, since the ticklabels overlap.

Any idea?

I really appreciate your help!

Is this what you are looking for?

http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html#insetlocator

Cheers!
Ben Root

This is supposed to work, and my quick test did work. Can you post a
complete but simple exampl?

Regards,

-JJ

···

On Mon, Aug 20, 2012 at 10:50 PM, darkside <in.the.darkside@...287...> wrote:

I am using zoomed_inset_axes, but the default position overlaps the yticks
and the parent axe ticks, so I am trying:
axins = zoomed_inset_axes(ax,
3,bbox_to_anchor(0.5,1),bbox_transform=ax.figure.transFigure, loc=2)

Thank you for your help.

A simple example that doesn’t work for me is:

···

import pylab as p
import numpy as np
from mpl_toolkits.axes_grid.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid.inset_locator import mark_inset
from mpl_toolkits.axes_grid.anchored_artists import AnchoredSizeBar
from matplotlib.ticker import MaxNLocator

fig = p.figure(figsize=(12,8))
ax = p.subplot(111)

z = p.arange(0,1.415,0.01)
d = z**2+np.random.random(len(z))

ax.plot(z,d,‘ro’,label=‘text’)

p.xlabel(‘z’,fontsize=18)
p.ylabel(‘Luminosity distance’,fontsize=18)
p.grid(True)

axins = zoomed_inset_axes(ax, 3,bbox_to_anchor=(0.5,0.5),bbox_transform=ax.figure.transFigure, loc=2)

axins.plot(z,d,‘r.’)

ax.legend(loc=2,bbox_to_anchor=(1,1))

x,y = (0.86,1.3)
x2,y2 = (1,1.7)
axins.set_xlim(x,x2)
axins.set_ylim(y,y2)
axins.tick_params(axis=‘both’,labelsize=12)
axins.xaxis.set_major_locator(MaxNLocator(2))
axins.yaxis.set_major_locator(MaxNLocator(3))

mark_inset(ax,axins,loc1=1,loc2=3, fc=“none”, ec=“0.5”)

p.draw()
p.show()

The “bbox_to_anchor” label is supposed to move the zoomed axis, but it does nothing, no matter what two numbers I place there.
I guess that I miss something, but I can’t figure out what. I really appreciate your help.

Best regards,
Illa

2012/9/5 Jae-Joon Lee <lee.j.joon@…287…>

On Mon, Aug 20, 2012 at 10:50 PM, darkside <in.the.darkside@…287…> wrote:

I am using zoomed_inset_axes, but the default position overlaps the yticks

and the parent axe ticks, so I am trying:

axins = zoomed_inset_axes(ax,

3,bbox_to_anchor(0.5,1),bbox_transform=ax.figure.transFigure, loc=2)

This is supposed to work, and my quick test did work. Can you post a

complete but simple exampl?

Regards,

-JJ

Your code works as expected in my side.
So, changing (0.5, 0.5) to something like (0.6, 0.5) has no effect in
your side?
Hmm, what is you matplotlib version? Maybe this is a bug in old
version of matplotlib.

Regards,

-JJ

···

On Wed, Sep 12, 2012 at 6:16 PM, darkside <in.the.darkside@...287...> wrote:

Thank you for your help.

A simple example that doesn't work for me is:
----------------------------------------
import pylab as p
import numpy as np
from mpl_toolkits.axes_grid.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid.inset_locator import mark_inset
from mpl_toolkits.axes_grid.anchored_artists import AnchoredSizeBar
from matplotlib.ticker import MaxNLocator

fig = p.figure(figsize=(12,8))
ax = p.subplot(111)

z = p.arange(0,1.415,0.01)
d = z**2+np.random.random(len(z))

ax.plot(z,d,'ro',label='text')

p.xlabel('z',fontsize=18)
p.ylabel('Luminosity distance',fontsize=18)
p.grid(True)

axins = zoomed_inset_axes(ax,
3,bbox_to_anchor=(0.5,0.5),bbox_transform=ax.figure.transFigure, loc=2)

axins.plot(z,d,'r.')

ax.legend(loc=2,bbox_to_anchor=(1,1))

x,y = (0.86,1.3)
x2,y2 = (1,1.7)
axins.set_xlim(x,x2)
axins.set_ylim(y,y2)
axins.tick_params(axis='both',labelsize=12)
axins.xaxis.set_major_locator(MaxNLocator(2))
axins.yaxis.set_major_locator(MaxNLocator(3))

mark_inset(ax,axins,loc1=1,loc2=3, fc="none", ec="0.5")

p.draw()
p.show()
-----------------------------------------------------------
The "bbox_to_anchor" label is supposed to move the zoomed axis, but it does
nothing, no matter what two numbers I place there.
I guess that I miss something, but I can't figure out what. I really
appreciate your help.

Best regards,
Illa

2012/9/5 Jae-Joon Lee <lee.j.joon@...287...>

On Mon, Aug 20, 2012 at 10:50 PM, darkside <in.the.darkside@...287...> >> wrote:
> I am using zoomed_inset_axes, but the default position overlaps the
> yticks
> and the parent axe ticks, so I am trying:
> axins = zoomed_inset_axes(ax,
> 3,bbox_to_anchor(0.5,1),bbox_transform=ax.figure.transFigure, loc=2)

This is supposed to work, and my quick test did work. Can you post a
complete but simple exampl?

Regards,

-JJ

[replying only to the list -Dale]

Your code works as expected in my side.

I wasn't quite sure what to expect, but based on Jae-Joon's note:

So, changing (0.5, 0.5) to something like (0.6, 0.5) has no effect in
your side?

It seems to work on my installation. I actually changed to (0.3,0.5) which made a nice view.

Hmm, what is you matplotlib version?

OS X 10.7.4 using python and tools from fink:
i python27 1:2.7.3-1
i python27-shlibs 1:2.7.3-1
i matplotlib-basemap-py27 1.0.2-1
i matplotlib-py27 1.1.1-1
i numpy-py27 1.6.1-1

Thanks to the folks who make this work,
-Dale

···

On Sep 12, 2012, at 07:02 , Jae-Joon Lee wrote:

Maybe this is a bug in old version of matplotlib.

Regards,

-JJ

On Wed, Sep 12, 2012 at 6:16 PM, darkside <in.the.darkside@...287...> wrote:

Thank you for your help.

A simple example that doesn't work for me is:
----------------------------------------
import pylab as p
import numpy as np
from mpl_toolkits.axes_grid.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid.inset_locator import mark_inset
from mpl_toolkits.axes_grid.anchored_artists import AnchoredSizeBar
from matplotlib.ticker import MaxNLocator

fig = p.figure(figsize=(12,8))
ax = p.subplot(111)

z = p.arange(0,1.415,0.01)
d = z**2+np.random.random(len(z))

ax.plot(z,d,'ro',label='text')

p.xlabel('z',fontsize=18)
p.ylabel('Luminosity distance',fontsize=18)
p.grid(True)

axins = zoomed_inset_axes(ax,
3,bbox_to_anchor=(0.5,0.5),bbox_transform=ax.figure.transFigure, loc=2)

axins.plot(z,d,'r.')

ax.legend(loc=2,bbox_to_anchor=(1,1))

x,y = (0.86,1.3)
x2,y2 = (1,1.7)
axins.set_xlim(x,x2)
axins.set_ylim(y,y2)
axins.tick_params(axis='both',labelsize=12)
axins.xaxis.set_major_locator(MaxNLocator(2))
axins.yaxis.set_major_locator(MaxNLocator(3))

mark_inset(ax,axins,loc1=1,loc2=3, fc="none", ec="0.5")

p.draw()
p.show()
-----------------------------------------------------------
The "bbox_to_anchor" label is supposed to move the zoomed axis, but it does
nothing, no matter what two numbers I place there.
I guess that I miss something, but I can't figure out what. I really
appreciate your help.

Best regards,
Illa

2012/9/5 Jae-Joon Lee <lee.j.joon@...287...>

On Mon, Aug 20, 2012 at 10:50 PM, darkside <in.the.darkside@...287...> >>> wrote:

I am using zoomed_inset_axes, but the default position overlaps the
yticks
and the parent axe ticks, so I am trying:
axins = zoomed_inset_axes(ax,
3,bbox_to_anchor(0.5,1),bbox_transform=ax.figure.transFigure, loc=2)

This is supposed to work, and my quick test did work. Can you post a
complete but simple exampl?

Regards,

-JJ

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Exactly, changing (0.5, 0.5) to something like (0.6, 0.5) has no effect in my side.

My python version is: 2.7.2
and matplotlib: 1.1.0

So maybe is a version problem, but it’s the work computer so I can’t update easily anything. I will try other computer.

Thank you all for your help,
Illa

2012/9/12 Dale Chayes <dale.chayes@…4197…>

···

[replying only to the list -Dale]

On Sep 12, 2012, at 07:02 , Jae-Joon Lee wrote:

Your code works as expected in my side.

I wasn’t quite sure what to expect, but based on Jae-Joon’s note:

So, changing (0.5, 0.5) to something like (0.6, 0.5) has no effect in

your side?

It seems to work on my installation. I actually changed to (0.3,0.5) which made a nice view.

Hmm, what is you matplotlib version?

OS X 10.7.4 using python and tools from fink:

i python27 1:2.7.3-1

i python27-shlibs 1:2.7.3-1

i matplotlib-basemap-py27 1.0.2-1

i matplotlib-py27 1.1.1-1

i numpy-py27 1.6.1-1

Thanks to the folks who make this work,

-Dale

Maybe this is a bug in old version of matplotlib.

Regards,

-JJ

On Wed, Sep 12, 2012 at 6:16 PM, darkside <in.the.darkside@…287…> wrote:

Thank you for your help.

A simple example that doesn’t work for me is:


import pylab as p

import numpy as np

from mpl_toolkits.axes_grid.inset_locator import zoomed_inset_axes

from mpl_toolkits.axes_grid.inset_locator import mark_inset

from mpl_toolkits.axes_grid.anchored_artists import AnchoredSizeBar

from matplotlib.ticker import MaxNLocator

fig = p.figure(figsize=(12,8))

ax = p.subplot(111)

z = p.arange(0,1.415,0.01)

d = z**2+np.random.random(len(z))

ax.plot(z,d,‘ro’,label=‘text’)

p.xlabel(‘z’,fontsize=18)

p.ylabel(‘Luminosity distance’,fontsize=18)

p.grid(True)

axins = zoomed_inset_axes(ax,

3,bbox_to_anchor=(0.5,0.5),bbox_transform=ax.figure.transFigure, loc=2)

axins.plot(z,d,‘r.’)

ax.legend(loc=2,bbox_to_anchor=(1,1))

x,y = (0.86,1.3)

x2,y2 = (1,1.7)

axins.set_xlim(x,x2)

axins.set_ylim(y,y2)

axins.tick_params(axis=‘both’,labelsize=12)

axins.xaxis.set_major_locator(MaxNLocator(2))

axins.yaxis.set_major_locator(MaxNLocator(3))

mark_inset(ax,axins,loc1=1,loc2=3, fc=“none”, ec=“0.5”)

p.draw()

p.show()


The “bbox_to_anchor” label is supposed to move the zoomed axis, but it does

nothing, no matter what two numbers I place there.

I guess that I miss something, but I can’t figure out what. I really

appreciate your help.

Best regards,

Illa

2012/9/5 Jae-Joon Lee <lee.j.joon@…287…>

On Mon, Aug 20, 2012 at 10:50 PM, darkside <in.the.darkside@…287…> > > >>> wrote:

I am using zoomed_inset_axes, but the default position overlaps the

yticks

and the parent axe ticks, so I am trying:

axins = zoomed_inset_axes(ax,

3,bbox_to_anchor(0.5,1),bbox_transform=ax.figure.transFigure, loc=2)

This is supposed to work, and my quick test did work. Can you post a

complete but simple exampl?

Regards,

-JJ


Live Security Virtual Conference

Exclusive live event will cover all the ways today’s security and

threat landscape has changed and how IT managers can respond. Discussions

will include endpoint security, mobile security and the latest in malware

threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Live Security Virtual Conference

Exclusive live event will cover all the ways today’s security and

threat landscape has changed and how IT managers can respond. Discussions

will include endpoint security, mobile security and the latest in malware

threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users