Skip to main content

Artist for matplotlib to display a color bar

Project description

https://travis-ci.org/ppinard/matplotlib-colorbar.svg https://badge.fury.io/py/matplotlib-colorbar.svg https://codecov.io/github/ppinard/matplotlib-colorbar/coverage.svg?branch=master

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.

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

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: font properties of the label text, specified either as dict or fontconfig pattern (XML).

  • ticks: ticks location (default: minimal and maximal values)

  • ticklabels: a list of tick labels (same length as ticks argument)

  • ticklocation: location of the ticks: left or right for vertical oriented colorbar, bottom or top for horizontal oriented colorbar, or ``auto for automatic adjustment (right for vertical and bottom for horizontal oriented colorbar). (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)

Release notes

0.3.6

  • Fix deprecated usage of is_string_like

0.3.5

  • Fix: UserWarning This call to matplotlib.use() has no effect (#9)

Contributors

@cphyc and @jnth

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

matplotlib-colorbar-0.3.7.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

matplotlib_colorbar-0.3.7-py2.py3-none-any.whl (15.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file matplotlib-colorbar-0.3.7.tar.gz.

File metadata

  • Download URL: matplotlib-colorbar-0.3.7.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.8.1 pkginfo/1.4.1 requests/2.13.0 setuptools/34.3.3 requests-toolbelt/0.7.1 clint/0.5.1 CPython/3.4.3 Linux/4.4.0-138-generic

File hashes

Hashes for matplotlib-colorbar-0.3.7.tar.gz
Algorithm Hash digest
SHA256 c530d898b4a391a1827ade6fdc06856198ce73a855ca76f039b02ff6bfde2a44
MD5 4ff38ec677cd4b47b81092a5b821dafd
BLAKE2b-256 a13144db01f0a24cca8c351ca6e9319bfcd279719ed3928b7e85406b9091de8b

See more details on using hashes here.

File details

Details for the file matplotlib_colorbar-0.3.7-py2.py3-none-any.whl.

File metadata

  • Download URL: matplotlib_colorbar-0.3.7-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.8.1 pkginfo/1.4.1 requests/2.13.0 setuptools/34.3.3 requests-toolbelt/0.7.1 clint/0.5.1 CPython/3.4.3 Linux/4.4.0-138-generic

File hashes

Hashes for matplotlib_colorbar-0.3.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 64eeaf3f5fe9bb84c821c0b82984322ee1731466b80955b724d9ff8ae1ae8342
MD5 03b1286df2319ccaefa90a120359c49f
BLAKE2b-256 0e3585e3fe77d8cd825ae3ce1f52d1801fe08066bf25602c6cdc8264ce5d4339

See more details on using hashes here.

Supported by

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