GPy.plotting package

Introduction

GPy.plotting effectively extends models based on GPy.core.gp.GP (and other classes) by adding methods to plot useful charts. ‘matplotlib’, ‘plotly’ (online) and ‘plotly’ (offline) are supported. The methods in GPy.plotting (and child classes GPy.plotting.gpy_plot and GPy.plotting.matplot_dep) are not intended to be called directly, but rather are ‘injected’ into other classes (notably GPy.core.gp.GP). Documentation describing plots is best found associated with the model being plotted e.g. GPy.core.gp.GP.plot_confidence.

change_plotting_library(lib, **kwargs)[source]
inject_plotting()[source]
plotting_library()[source]
show(figure, **kwargs)[source]

Show the specific plotting library figure, returned by add_to_canvas().

kwargs are the plotting library specific options for showing/drawing a figure.

Submodules

GPy.plotting.Tango module

currentDark()[source]
currentLight()[source]
currentMedium()[source]
hex2rgb(hexcolor)[source]
nextDark()[source]
nextLight()[source]
nextMedium()[source]
reset()[source]

GPy.plotting.abstract_plotting_library module

class AbstractPlottingLibrary[source]

Bases: object

Set the defaults dictionary in the _defaults variable:

E.g. for matplotlib we define a file defaults.py and

set the dictionary of it here:

from . import defaults _defaults = defaults.__dict__
add_to_canvas(canvas, plots, legend=True, title=None, **kwargs)[source]

Add plots is a dictionary with the plots as the items or a list of plots as items to canvas.

The kwargs are plotting library specific kwargs!

E.g. in matplotlib this does not have to do anything to add stuff, but we set the legend and title.

!This function returns the updated canvas!

Parameters:
  • title – the title of the plot
  • legend – whether to plot a legend or not
annotation_heatmap(canvas, X, annotation, extent, label=None, **kwargs)[source]

Plot an annotation heatmap. That is like an imshow, but put the text of the annotation inside the cells of the heatmap (centered).

Parameters:
  • canvas – the canvas to plot on
  • annotation (array-like) – the annotation labels for the heatmap
  • extent ([horizontal_min,horizontal_max,vertical_min,vertical_max]) – the extent of where to place the heatmap
  • label (str) – the label for the heatmap
Returns:

a list of both the heatmap and annotation plots [heatmap, annotation], or the interactive update object (alone)

annotation_heatmap_interact(canvas, plot_function, extent, label=None, resolution=15, **kwargs)[source]

if plot_function is not None, return an interactive updated heatmap, which updates on axis events, so that one can zoom in and out and the heatmap gets updated. See the matplotlib implementation in matplot_dep.controllers.

the plot_function returns a pair (X, annotation) to plot, when called with a new input X (which would be the grid, which is visible on the plot right now)

Parameters:
  • canvas – the canvas to plot on
  • annotation (array-like) – the annotation labels for the heatmap
  • extent ([horizontal_min,horizontal_max,vertical_min,vertical_max]) – the extent of where to place the heatmap
  • label (str) – the label for the heatmap
  • plot_function – the function, which generates new data for given input locations X
  • resolution (int) – the resolution of the interactive plot redraw - this is only needed when giving a plot_function
Returns:

a list of both the heatmap and annotation plots [heatmap, annotation], or the interactive update object (alone)

barplot(canvas, x, height, width=0.8, bottom=0, color=None, label=None, **kwargs)[source]

Plot vertical bar plot centered at x with height and width of bars. The y level is at bottom.

the kwargs are plotting library specific kwargs!

Parameters:
  • x (array-like) – the center points of the bars
  • height (array-like) – the height of the bars
  • width (array-like) – the width of the bars
  • bottom (array-like) – the start y level of the bars
  • kwargs – kwargs for the specific library you are using.
contour(canvas, X, Y, C, Z=None, color=None, label=None, **kwargs)[source]

Make a contour plot at (X, Y) with heights/colors stored in C on the canvas.

if Z is not None: make 3d contour plot at (X, Y, Z) with heights/colors stored in C on the canvas.

the kwargs are plotting library specific kwargs!

figure(nrows, ncols, **kwargs)[source]

Get a new figure with nrows and ncolumns subplots. Does not initialize the canvases yet.

There is individual kwargs for the individual plotting libraries to use.

fill_between(canvas, X, lower, upper, color=None, label=None, **kwargs)[source]

Fill along the xaxis between lower and upper.

the kwargs are plotting library specific kwargs!

fill_gradient(canvas, X, percentiles, color=None, label=None, **kwargs)[source]

Plot a gradient (in alpha values) for the given percentiles.

the kwargs are plotting library specific kwargs!

imshow(canvas, X, extent=None, label=None, vmin=None, vmax=None, **kwargs)[source]

Show the image stored in X on the canvas.

The origin of the image show is (0,0), such that X[0,0] gets plotted at [0,0] of the image!

the kwargs are plotting library specific kwargs!

imshow_interact(canvas, plot_function, extent=None, label=None, vmin=None, vmax=None, **kwargs)[source]

This function is optional!

Create an imshow controller to stream the image returned by the plot_function. There is an imshow controller written for mmatplotlib, which updates the imshow on changes in axis.

The origin of the image show is (0,0), such that X[0,0] gets plotted at [0,0] of the image!

the kwargs are plotting library specific kwargs!

new_canvas(figure=None, col=1, row=1, projection='2d', xlabel=None, ylabel=None, zlabel=None, title=None, xlim=None, ylim=None, zlim=None, **kwargs)[source]

Return a canvas, kwargupdate for your plotting library.

if figure is not None, create a canvas in the figure at subplot position (col, row).

This method does two things, it creates an empty canvas and updates the kwargs (deletes the unnecessary kwargs) for further usage in normal plotting.

the kwargs are plotting library specific kwargs!

Parameters:projection ({'2d'|'3d'}) – The projection to use.

E.g. in matplotlib this means it deletes references to ax, as plotting is done on the axis itself and is not a kwarg.

Parameters:
  • xlabel – the label to put on the xaxis
  • ylabel – the label to put on the yaxis
  • zlabel – the label to put on the zaxis (if plotting in 3d)
  • title – the title of the plot
  • legend – if True, plot a legend, if int make legend rows in the legend
  • float) xlim ((float,) – the limits for the xaxis
  • float) ylim ((float,) – the limits for the yaxis
  • float) zlim ((float,) – the limits for the zaxis (if plotting in 3d)
plot(cavas, X, Y, Z=None, color=None, label=None, **kwargs)[source]

Make a line plot from for Y on X (Y = f(X)) on the canvas. If Z is not None, plot in 3d!

the kwargs are plotting library specific kwargs!

plot_axis_lines(ax, X, color=None, label=None, **kwargs)[source]

Plot lines at the bottom (lower boundary of yaxis) of the axis at input location X.

If X is two dimensional, plot in 3d and connect the axis lines to the bottom of the Z axis.

the kwargs are plotting library specific kwargs!

scatter(canvas, X, Y, Z=None, color=None, vmin=None, vmax=None, label=None, **kwargs)[source]

Make a scatter plot between X and Y on the canvas given.

the kwargs are plotting library specific kwargs!

Parameters:
  • canvas – the plotting librarys specific canvas to plot on.
  • X (array-like) – the inputs to plot.
  • Y (array-like) – the outputs to plot.
  • Z (array-like) – the Z level to plot (if plotting 3d).
  • c (array-like) – the colorlevel for each point.
  • vmin (float) – minimum colorscale
  • vmax (float) – maximum colorscale
  • kwargs – the specific kwargs for your plotting library
show_canvas(canvas, **kwargs)[source]

Draw/Plot the canvas given.

surface(canvas, X, Y, Z, color=None, label=None, **kwargs)[source]

Plot a surface for 3d plotting for the inputs (X, Y, Z).

the kwargs are plotting library specific kwargs!

xerrorbar(canvas, X, Y, error, color=None, label=None, **kwargs)[source]

Make an errorbar along the xaxis for points at (X,Y) on the canvas. if error is two dimensional, the lower error is error[:,0] and the upper error is error[:,1]

the kwargs are plotting library specific kwargs!

yerrorbar(canvas, X, Y, error, color=None, label=None, **kwargs)[source]

Make errorbars along the yaxis on the canvas given. if error is two dimensional, the lower error is error[0, :] and the upper error is error[1, :]

the kwargs are plotting library specific kwargs!

defaults