Thank you for your fast reply,
you are right, AnchoredSizeBar has indeed almost all features I would
like. Or it definitely has the most important ones.
I have stumbled upon the page you refer, but I must have overlooked it.
An actual documentation of the function wouldn't hurt
Anyway, these features seem to be missing:
- Bar styles (bar width, bar endings wouldn't hurt either).
- Colors (bar, text, background).
I would like to look into it, but it is usually more efficient if more
experienced persons provide some pointers. So if you think that I should
know something before attempting to add the functionality, please let me
For instance, do you think that the enhancements I have proposed make
sense and should be integrated into AnchoredSizeBar?
On 11/18/2012 06:32 PM, Joe Kington wrote:
> Have you had a look at "AnchoredSizeBar" from
> It provides essentially all of the features you mention. I'd agree it
> could use a few enhancements, but it's a good start on this.
> As a quick example of using it as you describe:
> import matplotlib.pyplot as plt
> import numpy as np
> from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
> fig, ax = plt.subplots()
> bar = AnchoredSizeBar(ax.transData, 2, '2 Units',
> pad=0.5, loc=8, sep=5, borderpad=0.5, frameon=True)
> bar.patch.set(alpha=0.5, boxstyle='round')
> Note that this is very similar to your example. The main things it's
> missing are ends on the scalebar.
> I'd certainly agree that it could use some enhancements (e.g.
> different styles of scalebars and better documentation), but perhaps
> it's best to start with AnchoredSizeBar instead of recreating it from
> Just my thoughts, anyway.
> On Sun, Nov 18, 2012 at 8:16 AM, Matěj Týč <matej.tyc@...
> <mailto:matej.tyc@...>> wrote:
> Dear developers,
> I use Matplotlib to process and display images acquired by
> It is quite common to indicate dimensions by displaying scale bar
> in the
> image rather than using axes with labels. Although axes enable you to
> refer to specific location in the image, they take up space around the
> image, so if you only need to show the scale, scale bar is better.
> What is needed:
> - The scale bar of given dimension (data units), possibly with
> bars at
> its ends.
> - Text (presumably centered under the bar), text size as well as
> vertical offset in physical units (= units reflecting the actual image
> size, like the font size)
> - Semi-transparent rectangle, so the scale and label are more
> - Dark/bright theme might be a good idea.
> I have made an svg file in Inkscape, so you can see what I mean.
> First of all, I tried to implement the stuff myself, but later I have
> found out that there is something on github. I have forked it,
> made some
> minor modifications, and I think that it is "almost done".
> https://gist.github.com/4100881 (the add_scalebar function there is
> broken ATM)
> I also attach the test code for your convenience. You need to run it
> with scalebars.py in the same directory.
> You are supposed to see a tiny bright scalebar at the bottom right
> There are some outstanding issues, though:
> - I have a feeling that bars at the end of the scale bar should be
> related to the font size, as well as the actual width of the scale
> How to achieve this?
> - How to make the semi-transparent background for the bar and
> label in
> a smart way?
> Could you help me with those? I would like this to appear in
> since it is IMO a useful feature, what needs to be done?
> Matěj Týč
> Monitor your physical, virtual and cloud infrastructure from a single
> web console. Get in-depth insight into apps, servers, databases,
> SAP, cloud infrastructure, etc. Download 30-day Free Trial.
> Pricing starts from $795 for 25 servers or applications!
> Matplotlib-devel mailing list