sizebars at fixed location

Hi all,

I am trying to add to the axes a sizebar (a line of length specified in data coordinates) at a fixed location relative to the axes (in axes coordinates). The idea is that I have several subplots with different scales and I want to add scalebar at the same position to each of them.

I tried using ScaledTranslation transformation, but with no success (after export to SVG the scalebars are gone). I thought that I might use OffsetBox (the same that the legend is based on), but I have no idea how to use it.

Do you have any suggestions?

Thanks,

Bartosz

Hi again,

I found an example that implements something like I described:

http://matplotlib.sourceforge.net/examples/pylab_examples/anchored_artists.html?highlight=size%20bar

However, it did not allow to set arbitrary position. I modified the example to provide the anchor_to_bbox argument of AnchoredOffsetbox that allows to set the scale bars position in axes coordinates. The big gotcha is that you have to provide the loc argument to fix the that point should be adjusted to the coordinates (1 for upper right, 2 for upper left, see the docs of legend for all the codes). This is not clear in the documentation.

In the example attached, I add two scalebars: vertical and horizontal that cross at the lower right corner.

Bartosz

anchored_scalebar.py (2.92 KB)

Bartosz,

I am glad you found a solution. I will admit that the possibilities with the bbox anchor isn’t very clear. I am starting to tag all emails where users comment of deficiencies in the documentation. I plan to use this approach as a “TODO” list for documentation updates.

Cheers!
Ben Root

···

On Tue, Feb 21, 2012 at 9:56 AM, Bartosz Telenczuk <b.telenczuk@…2786…> wrote:

Hi again,

I found an example that implements something like I described:

http://matplotlib.sourceforge.net/examples/pylab_examples/anchored_artists.html?highlight=size%20bar

However, it did not allow to set arbitrary position. I modified the example to provide the anchor_to_bbox argument of AnchoredOffsetbox that allows to set the scale bars position in axes coordinates. The big gotcha is that you have to provide the loc argument to fix the that point should be adjusted to the coordinates (1 for upper right, 2 for upper left, see the docs of legend for all the codes). This is not clear in the documentation.

In the example attached, I add two scalebars: vertical and horizontal that cross at the lower right corner.

Bartosz