Index

Module Index

Search Page

npplus.pyplotx package

Matplotlib interactive usability enhancements.

Improvements to the pyplot interactive mode.


npplus.pyplotx.interactive module

Set up for interactive plotting with matplotlib.pylab.

Put this in your PYTHONSTARTUP file:

from npplus.pyplotx.interactive import *
# uncomment to get default npplus style (outward ticks, no box)
#style_npp()
# uncomment to get inward ticks and box
#style_npp(box=True)

You do not need to import npplus.interactive if you import npplus.pyplotx.interactive, it will be done automatically.


npplus.pyplotx.pltwraps module

Interactive wrappers for interactive use of various pyplot APIs.

Functions like matplotlib.pyplot.plot(x,y) are usually invoked as subroutine calls interactively, but inconveniently return an object which prints at the terminal. This module wraps such functions to return None, so that an interactive terminal isn’t half filled with unwanted object outputs. In the rare cases in which you need the return value, you can easily use, e.g.- result = plt.plot(x,y).

Also provides the convenience functions xylim and logxy.


logxy(islog=None, islogy=Ellipsis)[source]

Alternative to xscale, yscale for setting log or linear axes.

Parameters
  • islog (bool, optional) – True means to use log scale for axes, False means linear scale. None or omitted means leave axis scaling unchanged.

  • islogy (bool, optional) – If islogy omitted, islog applies to both x and y axes. If islogy provided, islog applies only to the x axis and islogy applies to the y axis; values have the same meaning as for islog.

xylim(xmin=None, xmax=None, ymin=None, ymax=None)[source]

Set xmin, xmax, ymin, ymax limits for the current axes, return None.

Parameters
  • xmin (float, optional) – Axis limit or None to leave unchanged.

  • xmax (float, optional) – Axis limit or None to leave unchanged.

  • ymin (float, optional) – Axis limit or None to leave unchanged.

  • ymax (float, optional) – Axis limit or None to leave unchanged.

See also

matplotlib.pyplot.axis

get or set limits for current axes

Notes

The xylim function avoids the need for passing a tuple to axis, and has no return value, to avoid printing a value. It is strictly a convenience function for interactive use; use axis in scripts.

npplus.pyplotx.mpldefaults module

Provide some matplotlib default settings and repackaging.

Exposes magma, inferno, plasma, and viridis colormaps, and CBQ object encapsulating the ColorBrewer qualitative palettes for use as color cycles.

Provides style_npp() function to set nicer default matplotlib style:

  1. Ensure matplotlib 2.0 colormaps present and viridis default.

  2. Simple CBQ interface for ColorBrewer color sets for linestyle cycling. Make default color cycle based on ColorBrewer Set1 (minus yellow).

  3. Fix savefig bounding box default to not clip title and labels.

  4. Make imshow not change viewport aspect by default.

  5. Change to a more yorick-like default plot style, with much larger axis labels, outward ticks, and a much subtler background.

  6. Define title function that works with outward ticks.


class CBQ[source]

Container for ColorBrewer qualitative color sets.

These are good choices for line color cycles, in addition to maps meant to distinguish twelve or fewer different regions. Only the first three set2 and dark2 colors and the first four paired colors are colorblind safe. Mostly these sets are distinguished by hue, with the colors in a set similar lightness and saturation:

set1, pastel1            9 colors
set2, pastel2, dark2     8 colors
set3                    12 colors
accent                   8 colors
paired                  12 colors

set1 darkest, most saturated
dark2 next darkest, less saturated
accent 4 lighter colors followed by 4 darker colors
set2 more uniform about same darkness as lighter accent colors
set3 intermediate between darker and more pastel sets
pastel1 more variable lightness, more saturated than pastel2
pastel2 lightest, least saturated
paired[0::2] are pastel corresponding to darker paired[1::2]
   pastels are about at set3 lightness, darks about at set1

The yellow color in set1, pastel1, set3, accent, and paired is not visible against white. All other colors contrast with both white and black. The following modified sets omit the yellow color:

set1ny, pastel1ny      8 colors
set3ny                11 colors
accentny               7 colors

Do not use the final pair in paired, that is use only paired[0:10], to avoid the yellow (which is paired[10]).

classmethod set_color_cycle(name, axes=None)[source]

Set the color cycle for future plot commands.

Parameters
  • name (str) – One of the color set names, see help(CBQ).

  • axes (Axes, optional) – If not provided, sets the default color cycle in the rcParams axes section. Otherwise, sets the color cycle for the given axes.

style_npp(box=None, cycle='set1ny')[source]

Set rcParams for nicer style than matplotlib defaults.

Parameters
  • box (bool, optional) – If set, inward ticks with box drawn around the plot. By default, the style is less traditional with outward ticks that can never obscure data and no box around the plot.

  • cycle (str, optional) – Color cycle to use for plot curves, ‘set1ny’ by default. Specify ‘’ to get Matplotlib default.

Notes

Other features are:

  • Matplotlib 2.0 viridis colormap becomes default.

  • Color cycle for plot lines derived from ColorBrewer Set1.

  • Heavier lines and larger axis numbering.

  • Images displayed with imshow do not change aspect ratio of axes.

  • The savefig command set up to not clip axis labels or title.

  • The background of figure and axes differ more subtlely on screen.