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(…).
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 clone git@github.com:ppinard/matplotlib-scalebar.git $ 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()
The scale bar also works with reciprocal units,:
>>> from matplotlib_scalebar.scalebar import SI_LENGTH_RECIPROCAL >>> scalebar = ScaleBar(0.2, '1/cm', SI_LENGTH_RECIPROCAL) # 1 pixel = 0.2 1/cm
imperial units:
>>> from matplotlib_scalebar.scalebar import IMPERIAL_LENGTH >>> scalebar = ScaleBar(0.2, 'ft', IMPERIAL_LENGTH) # 1 pixel = 0.2 feet
and system defined by the Dimension class.
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: font properties of the label text, specified either as dict or fontconfig pattern (XML).
License
License under the BSD License, compatible with matplotlib.
Copyright (c) 2015 Philippe Pinard
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file matplotlib-scalebar-0.2.0.tar.gz
.
File metadata
- Download URL: matplotlib-scalebar-0.2.0.tar.gz
- Upload date:
- Size: 25.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0344f6b5a4425b53249f5df7110546d52c0305e758a974de95b76d831e72c56 |
|
MD5 | bdbb96ab908200cb16d19af51526ccee |
|
BLAKE2b-256 | 631aa3431b3b3a8f2cfa6d9c071419a06e74ef2f43703885ba1c103b4f6e30a3 |
File details
Details for the file matplotlib_scalebar-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: matplotlib_scalebar-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8a32774d466a26ba3bb4228c766dcfecf4eb55a1e20e8b1d8670d87431e95b2 |
|
MD5 | 77e6d3b5069000ebac79775f1bf730f9 |
|
BLAKE2b-256 | 229a334e776bc88e01ab92f522be73ee373e0413a91e5689839f77b92a09a7e6 |