colors module of the psyplot package.

This module contains some additional color maps and the show_colormaps function to visualize available colormaps.

Classes:

FixedBoundaryNorm(boundaries, ncolors[, ...])

Bug fixing Norm with same functionality as matplotlibs BoundaryNorm

FixedColorMap(name, segmentdata[, N, gamma])

Bug fixing colormap with same functionality as matplotlibs colormap

Functions:

get_cmap(name[, lut])

Returns the specified colormap.

show_colormaps([names, N, show, use_qt])

Function to show standard colormaps from pyplot

class psy_simple.colors.FixedBoundaryNorm(boundaries, ncolors, clip=False, *, extend='neither')

Bases: BoundaryNorm

Bug fixing Norm with same functionality as matplotlibs BoundaryNorm

This class fixes a bug in the cartopy.mpl.geoaxes.GeoAxes.streamplot() for matplotlib version 1.5

Notes

To reproduce the error type:

>>> import cartopy.crs as ccrs
>>> import matplotlib.pyplot as plt
>>> import psyplot.project as psy
>>> import matplotlib.colors as mcol
>>> maps = psy.plot.mapvector(
...     "test-t2m-u-v.nc",
...     name=[["u", "v"]],
...     plot="stream",
...     lonlatbox="Europe",
...     color="absolute",
... )
>>> plotter = maps[0].plotter
>>> x, y, u, v = plotter.plot._get_data()
>>> maps.close(True, True)
>>> ax = plt.axes(projection=ccrs.PlateCarree())
>>> ax.set_extent(plotter.lonlatbox.lonlatbox, crs=ccrs.PlateCarree())
>>> m = ax.streamplot(
...     x,
...     y,
...     u,
...     v,
...     color=plotter.plot._kwargs["color"],
...     norm=mcol.BoundaryNorm(
...         plotter.bounds.norm.boundaries,
...         plotter.bounds.norm.Ncmap,
...         plotter.bounds.norm.clip,
...     ),
...     density=[1.0, 1.0],
... )

This raises in matplotlib.colors, line 1316, in matplotlib.colors.BoundaryNorm.__call__():

``ret = int(ret[0])  # assume python scalar``
MaskError: Cannot convert masked element to a Python int.
class psy_simple.colors.FixedColorMap(name, segmentdata, N=256, gamma=1.0)

Bases: LinearSegmentedColormap

Bug fixing colormap with same functionality as matplotlibs colormap

This class fixes a bug in the cartopy.mpl.geoaxes.GeoAxes.streamplot() method in python 3.4

Notes

To reproduce the error type in python 3.4:

>>> import cartopy.crs as ccrs
>>> import matplotlib.pyplot as plt
>>> import psyplot.project as psy
>>> maps = psy.plot.mapvector(
...     "test-t2m-u-v.nc",
...     name=[["u", "v"]],
...     plot="stream",
...     lonlatbox="Europe",
...     color="absolute",
... )
>>> plotter = maps[0].plotter
>>> x, y, u, v = plotter.plot._get_data()
>>> maps.close(True, True)
>>> ax = plt.axes(projection=ccrs.PlateCarree())
>>> ax.set_extent(plotter.lonlatbox.lonlatbox, crs=ccrs.PlateCarree())
>>> m = ax.streamplot(
...     x,
...     y,
...     u,
...     v,
...     density=[1.0, 1.0],
...     color=plotter.plot._kwargs["color"],
...     norm=plotter.plot._kwargs["norm"],
... )

This raises in matplotlib.colors, line 557, in matplotlib.colors.Colormap.__call__():

``xa = np.array([X])``
ValueError: setting an array element with a sequence.

Methods:

from_list(*args, **kwargs)

Create a LinearSegmentedColormap from a list of colors.

static from_list(*args, **kwargs)

Create a LinearSegmentedColormap from a list of colors.

Parameters:
  • name (str) – The name of the colormap.

  • colors (array-like of colors or array-like of (value, color)) – If only colors are given, they are equidistantly mapped from the range \([0, 1]\); i.e. 0 maps to colors[0] and 1 maps to colors[-1]. If (value, color) pairs are given, the mapping is from value to color. This can be used to divide the range unevenly.

  • N (int) – The number of RGB quantization levels.

  • gamma (float) –

psy_simple.colors.get_cmap(name, lut=None)

Returns the specified colormap.

Parameters:
  • name (str or matplotlib.colors.Colormap) –

    If a colormap, it returned unchanged.

    Strings may be any valid colormap name suitable for the matplotlib.cm.get_cmap() function or one of the color lists defined in the ‘colors.cmaps’ key of the psyplot.rcParams dictionary (including their reversed color maps given via the ‘_r’ extension).

  • lut (int) – An integer giving the number of entries desired in the lookup table

Returns:

The colormap specified by name

Return type:

matplotlib.colors.Colormap

See also

show_colormaps

A function to display all available colormaps

Notes

Different from the :func::matpltolib.pyplot.get_cmap function, this function changes the number of colors if name is a matplotlib.colors.Colormap instance to match the given lut.

psy_simple.colors.show_colormaps(names=[], N=10, show=True, use_qt=None)

Function to show standard colormaps from pyplot

Parameters:
  • *args (str or matplotlib.colors.Colormap) –

    If a colormap, it returned unchanged.

    Strings may be any valid colormap name suitable for the matplotlib.cm.get_cmap() function or one of the color lists defined in the ‘colors.cmaps’ key of the psyplot.rcParams dictionary (including their reversed color maps given via the ‘_r’ extension).

  • N (int, optional) – Default: 11. The number of increments in the colormap.

  • show (bool, optional) – Default: True. If True, show the created figure at the end with pyplot.show(block=False)

  • use_qt (bool) – If True, use the psy_simple.widgets.color.ColormapDialog.show_colormaps, if False use a matplotlib implementation based on [1]. If None, use the Qt implementation if it is running in the psyplot GUI.

Returns:

Depending on use_qt, either an instance of the psy_simple.widgets.color.ColormapDialog or the matplotlib.figure.Figure

Return type:

psy_simple.widgets.color.ColormapDialog or matplitlib.figure.Figure

References