Skip to main content

Artist for matplotlib to display a scale bar

Project description

Provides a new artist for matplotlib to display a scale bar, aka micron bar. It is particularly useful when displaying calibrated images plotted using plt.imshow(…).

https://raw.githubusercontent.com/ppinard/matplotlib-scalebar/master/doc/example1.png

The artist supports customization either directly from the Scalebar object or from the matplotlibrc.

Installation

Easiest way to install using pip:

$ pip install matplotlib-scalebar

For development installation from the git repository:

$ git pull
$ pip install -e matplotlib-scalebar

Example

Here is an example how to add a scale bar:

>>> import matplotlib.pyplot as plt
>>> import matplotlib.cbook as cbook
>>> from matplotlib_scalebar.scalebar import ScaleBar
>>> plt.figure()
>>> image = plt.imread(cbook.get_sample_data('grace_hopper.png'))
>>> plt.imshow(image)
>>> scalebar = ScaleBar(0.2) # 1 pixel = 0.2 meter
>>> plt.gca().add_artist(scalebar)
>>> plt.show()

matplotlibrc parameters

Here are parameters that can either be customized in the constructor of the ScaleBar class or in the matplotlibrc file.

  • scalebar.length_fraction: length of the scale bar as a fraction of the axes’s width (default: 0.2)

  • scalebar.height_fraction: height of the scale bar as a fraction of the axes’s height (default: 0.01)

  • scalebar.location: a location code (same as legend) (default: upper right)

  • scalebar.pad: fraction of the font size (default: 0.2)

  • scalebar.border_pad: fraction of the font size (default: 0.1)

  • scalebar.sep: separation between scale bar and label in points (default: 5)

  • scalebar.frameon: if True, will draw a box around the scale bar and label (default: True)

  • scalebar.color: color for the scale bar and label (default: k)

  • scalebar.box_color: color of the box (if frameon) (default: w)

  • scalebar.box_alpha: transparency of box (default: 1.0)

  • scalebar.label_top: if True, the label will be over the scale bar (default: False)

  • scalebar.font_properties: a matplotlib.font_manager.FontProperties instance, optional sets the font properties for the label text

License

License under the BSD License, compatible with matplotlib.

Copyright (c) 2015 Philippe Pinard

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matplotlib-scalebar-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matplotlib_scalebar-0.1.0-py2.py3-none-any.whl (9.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file matplotlib-scalebar-0.1.0.tar.gz.

File metadata

File hashes

Hashes for matplotlib-scalebar-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f8a2e15716d13f9e09e789c6b8c4522e1788a5e65ddebcf275cbf1b9979cdb6b
MD5 15fa1c4ee287d17e1deeb60793664a59
BLAKE2b-256 469b8c289035cf444058c29cd70d8b72ff6bdc6eb567d49562a21dd2131c0df0

See more details on using hashes here.

File details

Details for the file matplotlib_scalebar-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for matplotlib_scalebar-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ae9d596eb27bc40e5d46305dcee8997ac7cad8e399f98a8d90ddab4cc398f091
MD5 763fbe91df92694d34efdfb10188147a
BLAKE2b-256 0d556df3e9c58a7a62eb3d0751a7808168e068b271af99cd7c489ebc0fef0559

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page