Artist for matplotlib to display a color bar
Project description
Provides a new artist for matplotlib to display a colorbar, instead of an axis as it is the default in matplotlib. The position of the colorbar artist can be decided as for the legend.
The artist supports customization either directly from the Colorbar object or from the matplotlibrc.
Installation
Easiest way to install using pip:
$ pip install matplotlib-colorbar
For development installation from the git repository:
$ git clone git@github.com:ppinard/matplotlib-colorbar.git $ pip install -e matplotlib-colorbar
Example
Here is an example how to add a color bar:
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> import matplotlib.cbook as cbook >>> from matplotlib_colorbar.colorbar import Colorbar >>> plt.figure() >>> data = np.array(plt.imread(cbook.get_sample_data('grace_hopper.png'))) >>> mappable = plt.imshow(data[...,0], cmap='viridis') >>> colorbar = Colorbar(mappable, location='lower left') >>> colorbar.set_ticks([0.0, 0.5, 1.0]) >>> plt.gca().add_artist(colorbar) >>> plt.show()
Colorbar arguments
Here are parameters of the Colorbar class constructor.
mappable: scalar mappable object which implements the methods get_cmap and get_array (default: None, the mappable can be specified later)
label: label on top of the color bar (default: None, no label is shown)
orientation: orientation, vertical or horizontal (default: vertical)
length_fraction: length of the color bar as a fraction of the axes’s width (horizontal) or height (vertical) depending on the orientation (default: 0.2)
width_fraction: width of the color bar as a fraction of the axes’s height (horizontal) or width (vertical) depending on the orientation (default: 0.02)
location: a location code (same as legend) (default: upper right)
pad: fraction of the font size (default: 0.2)
border_pad: fraction of the font size (default: 0.1)
sep: separation between color bar and label in points (default: 5)
frameon: if True, will draw a box around the color bar (default: True)
color: color for the tick text and label (default: k)
box_color: color of the box (if frameon) (default: w)
box_alpha: transparency of box (default: 1.0)
font_properties: a matplotlib.font_manager.FontProperties instance, optional sets the font properties for the label text
ticks: ticks location (default: minimal and maximal values)
ticklabels: a list of tick labels (same length as ticks argument)
ticklocation: location of the ticks (default: auto)
matplotlibrc parameters
Here are parameters that can be customized in the matplotlibrc file.
orientation: orientation, vertical or horizontal (default: vertical)
length_fraction: length of the color bar as a fraction of the axes’s width (horizontal) or height (vertical) depending on the orientation (default: 0.2)
width_fraction: width of the color bar as a fraction of the axes’s height (horizontal) or width (vertical) depending on the orientation (default: 0.02)
location: a location code (same as legend) (default: upper right)
pad: fraction of the font size (default: 0.2)
border_pad: fraction of the font size (default: 0.1)
sep: separation between color bar and label in points (default: 5)
frameon: if True, will draw a box around the color bar (default: True)
color: color for the tick text and label (default: k)
box_color: color of the box (if frameon) (default: w)
box_alpha: transparency of box (default: 1.0)
ticklocation: location of the ticks (default: auto)
Contributors
License
License under the BSD License, compatible with matplotlib.
Copyright (c) 2015-2017 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
Built Distribution
File details
Details for the file matplotlib-colorbar-0.3.4.tar.gz
.
File metadata
- Download URL: matplotlib-colorbar-0.3.4.tar.gz
- Upload date:
- Size: 26.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd0d835e5086ba6a76fb9cc0f16bd9e5cd059769e1e5a0428576d794cf542a2a |
|
MD5 | 3d58c4370dcbd3fb1e4b126a9e4a0b3e |
|
BLAKE2b-256 | 1cf2ff3ba0defee31d5b6320b99e1011cb0a0d0e5c0004751bc8a4ff0ec3c8a2 |
File details
Details for the file matplotlib_colorbar-0.3.4-py2.py3-none-any.whl
.
File metadata
- Download URL: matplotlib_colorbar-0.3.4-py2.py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 849fee44601edd6229615091c7e55d66acf15c9a9c1e336c87ec89745e7b8145 |
|
MD5 | 02c77251f85e6f508ab41468b879c9f3 |
|
BLAKE2b-256 | 86fd67ecec191f1e63470fbf6dd01f9ea645c5263d027a306cfb139ed4114eee |