GPy.plotting.matplot_dep package

Submodules

GPy.plotting.matplot_dep.base_plots module

ax_default(fignum, ax)[source]
fewerXticks(ax=None, divideby=2)[source]
gperrors(x, mu, lower, upper, edgecol=None, ax=None, fignum=None, **kwargs)[source]
gpplot(x, mu, lower, upper, edgecol='#3300FF', fillcol='#33CCFF', ax=None, fignum=None, **kwargs)[source]
gradient_fill(x, percentiles, ax=None, fignum=None, **kwargs)[source]
meanplot(x, mu, color='#3300FF', ax=None, fignum=None, linewidth=2, **kw)[source]
removeRightTicks(ax=None)[source]
removeUpperTicks(ax=None)[source]
x_frame1D(X, plot_limits=None, resolution=None)[source]

Internal helper function for making plots, returns a set of input values to plot as well as lower and upper limits

x_frame2D(X, plot_limits=None, resolution=None)[source]

Internal helper function for making plots, returns a set of input values to plot as well as lower and upper limits

GPy.plotting.matplot_dep.defaults module

GPy.plotting.matplot_dep.img_plots module

The module contains the tools for ploting 2D image visualizations

plot_2D_images(figure, arr, symmetric=False, pad=None, zoom=None, mode=None, interpolation='nearest')[source]

GPy.plotting.matplot_dep.mapping_plots module

plot_mapping(self, plot_limits=None, which_data='all', which_parts='all', resolution=None, levels=20, samples=0, fignum=None, ax=None, fixed_inputs=[], linecol='#204a87')[source]
Plots the mapping associated with the model.
  • In one dimension, the function is plotted.
  • In two dimsensions, a contour-plot shows the function
  • In higher dimensions, we’ve not implemented this yet !TODO!

Can plot only part of the data and part of the posterior functions using which_data and which_functions

Parameters:
  • plot_limits (np.array) – The limits of the plot. If 1D [xmin,xmax], if 2D [[xmin,ymin],[xmax,ymax]]. Defaluts to data limits
  • which_data ('all' or a slice object to slice self.X, self.Y) – which if the training data to plot (default all)
  • which_parts ('all', or list of bools) – which of the kernel functions to plot (additively)
  • resolution (int) – the number of intervals to sample the GP on. Defaults to 200 in 1D and 50 (a 50x50 grid) in 2D
  • levels (int) – number of levels to plot in a contour plot.
  • samples (int) – the number of a posteriori samples to plot
  • fignum (figure number) – figure to plot on.
  • ax (axes handle) – axes to plot on.
  • fixed_inputs (a list of tuples) – a list of tuple [(i,v), (i,v)…], specifying that input index i should be set to value v.
  • linecol – color of line to plot.
  • levels – for 2D plotting, the number of contour levels to use is ax is None, create a new figure

GPy.plotting.matplot_dep.maps module

apply_bbox(sf, ax)[source]

Use bbox as xlim and ylim in ax

bbox_match(sf, bbox, inside_only=True)[source]

Return the geometry and attributes of a shapefile that lie within (or intersect) a bounding box

Parameters:
  • sf (shapefile object) – shapefile
  • bbox (list of floats [x_min,y_min,x_max,y_max]) – bounding box
Inside_only:

True if the objects returned are those that lie within the bbox and False if the objects returned are any that intersect the bbox

new_shape_string(sf, name, regex, field=2, type=None)[source]
plot(shape_records, facecolor='w', edgecolor='k', linewidths=0.5, ax=None, xlims=None, ylims=None)[source]

Plot the geometry of a shapefile

Parameters:
  • shape_records (ShapeRecord object (output of a shapeRecords() method)) – geometry and attributes list
  • facecolor – color to be used to fill in polygons
  • edgecolor – color to be used for lines
  • ax (axes handle) – axes to plot on.
plot_bbox(sf, bbox, inside_only=True)[source]

Plot the geometry of a shapefile within a bbox

Parameters:
  • sf (shapefile object) – shapefile
  • bbox (list of floats [x_min,y_min,x_max,y_max]) – bounding box
Inside_only:

True if the objects returned are those that lie within the bbox and False if the objects returned are any that intersect the bbox

plot_string_match(sf, regex, field, **kwargs)[source]

Plot the geometry of a shapefile whose fields match a regular expression given

Parameters:sf (shapefile object) – shapefile
Regex:regular expression to match
Field:field number to be matched with the regex
string_match(sf, regex, field=2)[source]

Return the geometry and attributes of a shapefile whose fields match a regular expression given

Parameters:sf (shapefile object) – shapefile
Regex:regular expression to match
Field:field number to be matched with the regex

GPy.plotting.matplot_dep.plot_definitions module

class MatplotlibPlots[source]

Bases: GPy.plotting.abstract_plotting_library.AbstractPlottingLibrary

add_to_canvas(ax, plots, legend=False, 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(ax, X, annotation, extent=None, label=None, imshow_kwargs=None, **annotation_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(ax, plot_function, extent, label=None, resolution=15, imshow_kwargs=None, **annotation_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(ax, x, height, width=0.8, bottom=0, color='#3465a4', 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(ax, X, Y, C, levels=20, 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(rows=1, cols=1, gridspec_kwargs={}, tight_layout=True, **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(ax, X, lower, upper, color='#3465a4', 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='#3465a4', label=None, **kwargs)[source]

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

the kwargs are plotting library specific kwargs!

imshow(ax, X, extent=None, label=None, vmin=None, vmax=None, **imshow_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(ax, plot_function, extent, label=None, resolution=None, vmin=None, vmax=None, **imshow_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, row=1, col=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(ax, 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='#a40000', 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(ax, X, Y, Z=None, color='#3465a4', label=None, marker='o', **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(ax, **kwargs)[source]

Draw/Plot the canvas given.

surface(ax, 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(ax, X, Y, error, color='#a40000', 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(ax, X, Y, error, color='#a40000', 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!

GPy.plotting.matplot_dep.priors_plots module

plot(prior)[source]
univariate_plot(prior)[source]

GPy.plotting.matplot_dep.ssgplvm module

The module plotting results for SSGPLVM

class SSGPLVM_plot(model, imgsize)[source]

Bases: object

plot_inducing()[source]

GPy.plotting.matplot_dep.svig_plots module

plot(model, ax=None, fignum=None, Z_height=None, **kwargs)[source]
plot_traces(model)[source]

GPy.plotting.matplot_dep.util module

align_subplot_array(axes, xlim=None, ylim=None)[source]

Make all of the axes in the array hae the same limits, turn off unnecessary ticks use plt.subplots() to get an array of axes

align_subplots(N, M, xlim=None, ylim=None)[source]

make all of the subplots have the same limits, turn off unnecessary ticks

fewerXticks(ax=None, divideby=2)[source]
fixed_inputs(model, non_fixed_inputs, fix_routine='median', as_list=True, X_all=False)[source]

Convenience function for returning back fixed_inputs where the other inputs are fixed using fix_routine :param model: model :type model: Model :param non_fixed_inputs: dimensions of non fixed inputs :type non_fixed_inputs: list :param fix_routine: fixing routine to use, ‘mean’, ‘median’, ‘zero’ :type fix_routine: string :param as_list: if true, will return a list of tuples with (dimension, fixed_val) otherwise it will create the corresponding X matrix :type as_list: boolean

legend_ontop(ax, mode='expand', ncol=3, fontdict=None)[source]
removeRightTicks(ax=None)[source]
removeUpperTicks(ax=None)[source]

GPy.plotting.matplot_dep.variational_plots module

plot(parameterized, fignum=None, ax=None, colors=None, figsize=(12, 6))[source]

Plot latent space X in 1D:

  • if fig is given, create input_dim subplots in fig and plot in these
  • if ax is given plot input_dim 1D latent space plots of X into each axis
  • if neither fig nor ax is given create a figure with fignum and plot in there
colors:
colors of different latent space dimensions input_dim
plot_SpikeSlab(parameterized, fignum=None, ax=None, colors=None, side_by_side=True)[source]

Plot latent space X in 1D:

  • if fig is given, create input_dim subplots in fig and plot in these
  • if ax is given plot input_dim 1D latent space plots of X into each axis
  • if neither fig nor ax is given create a figure with fignum and plot in there
colors:
colors of different latent space dimensions input_dim

GPy.plotting.matplot_dep.visualize module

class data_show(vals)[source]

Bases: object

The data_show class is a base class which describes how to visualize a particular data set. For example, motion capture data can be plotted as a stick figure, or images are shown using imshow. This class enables latent to data visualizations for the GP-LVM.

close()[source]
modify(vals)[source]
class image_show(vals, axes=None, dimensions=(16, 16), transpose=False, order='C', invert=False, scale=False, palette=[], preset_mean=0.0, preset_std=1.0, select_image=0, cmap=None)[source]

Bases: GPy.plotting.matplot_dep.visualize.matplotlib_show

Show a data vector as an image. This visualizer rehapes the output vector and displays it as an image.

Parameters:
  • vals (axes handle) – the values of the output to display.
  • axes – the axes to show the output on.
  • dimensions (tuple) – the dimensions that the image needs to be transposed to for display.
  • transpose – whether to transpose the image before display.
  • order (string) – whether array is in Fortan ordering (‘F’) or Python ordering (‘C’). Default is python (‘C’).
  • invert (bool) – whether to invert the pixels or not (default False).
  • palette – a palette to use for the image.
  • preset_mean (double) – the preset mean of a scaled image.
  • preset_std (double) – the preset standard deviation of a scaled image.
  • cmap (matplotlib.cm) – the colormap for image visualization
modify(vals)[source]
set_image(vals)[source]
class lvm(vals, model, data_visualize, latent_axes=None, sense_axes=None, latent_index=[0, 1], disable_drag=False)[source]

Bases: GPy.plotting.matplot_dep.visualize.matplotlib_show

Visualize a latent variable model

Parameters:
  • model – the latent variable model to visualize.
  • data_visualize (visualize.data_show type.) – the object used to visualize the data which has been modelled.
  • latent_axes – the axes where the latent visualization should be plotted.
modify(vals)[source]

When latent values are modified update the latent representation and ulso update the output visualization.

on_click(event)[source]
on_enter(event)[source]
on_leave(event)[source]
on_move(event)[source]
show_sensitivities()[source]
class lvm_dimselect(vals, model, data_visualize, latent_axes=None, sense_axes=None, latent_index=[0, 1], labels=None)[source]

Bases: GPy.plotting.matplot_dep.visualize.lvm

A visualizer for latent variable models which allows selection of the latent dimensions to use by clicking on a bar chart of their length scales.

For an example of the visualizer’s use try:

GPy.examples.dimensionality_reduction.BGPVLM_oil()

on_click(event)[source]
on_leave(event)[source]
class lvm_subplots(vals, Model, data_visualize, latent_axes=None, sense_axes=None)[source]

Bases: GPy.plotting.matplot_dep.visualize.lvm

latent_axes is a np array of dimension np.ceil(input_dim/2), one for each pair of the latent dimensions.

class matplotlib_show(vals, axes=None)[source]

Bases: GPy.plotting.matplot_dep.visualize.data_show

the matplotlib_show class is a base class for all visualization methods that use matplotlib. It is initialized with an axis. If the axis is set to None it creates a figure window.

close()[source]
class mocap_data_show(vals, axes=None, connect=None, color='b')[source]

Bases: GPy.plotting.matplot_dep.visualize.matplotlib_show

Base class for visualizing motion capture data.

draw_edges()[source]
draw_vertices()[source]
finalize_axes()[source]
finalize_axes_modify()[source]
initialize_axes(boundary=0.05)[source]

Set up the axes with the right limits and scaling.

initialize_axes_modify()[source]
modify(vals)[source]
process_values()[source]
class mocap_data_show_vpython(vals, scene=None, connect=None, radius=0.1)[source]

Bases: GPy.plotting.matplot_dep.visualize.vpython_show

Base class for visualizing motion capture data using visual module.

draw_edges()[source]
draw_vertices()[source]
modify(vals)[source]
modify_edges()[source]
modify_vertices()[source]
pos_axis(i, j)[source]
process_values()[source]
class skeleton_show(vals, skel, axes=None, padding=0, color='b')[source]

Bases: GPy.plotting.matplot_dep.visualize.mocap_data_show

data_show class for visualizing motion capture data encoded as a skeleton with angles.

data_show class for visualizing motion capture data encoded as a skeleton with angles. :param vals: set of modeled angles to use for printing in the axis when it’s first created. :type vals: np.array :param skel: skeleton object that has the parameters of the motion capture skeleton associated with it. :type skel: mocap.skeleton object :param padding: :type int

process_values()[source]

Takes a set of angles and converts them to the x,y,z coordinates in the internal prepresentation of the class, ready for plotting.

Parameters:vals – the values that are being modelled.
wrap_around(lim, connect)[source]
class stick_show(vals, connect=None, axes=None)[source]

Bases: GPy.plotting.matplot_dep.visualize.mocap_data_show

Show a three dimensional point cloud as a figure. Connect elements of the figure together using the matrix connect.

process_values()[source]

Convert vector of values into a matrix for use as a 3-D point cloud.

class vector_show(vals, axes=None)[source]

Bases: GPy.plotting.matplot_dep.visualize.matplotlib_show

A base visualization class that just shows a data vector as a plot of vector elements alongside their indices.

modify(vals)[source]
class vpython_show(vals, scene=None)[source]

Bases: GPy.plotting.matplot_dep.visualize.data_show

the vpython_show class is a base class for all visualization methods that use vpython to display. It is initialized with a scene. If the scene is set to None it creates a scene window.

close()[source]
data_play(Y, visualizer, frame_rate=30)[source]

Play a data set using the data_show object given.

Y:the data set to be visualized.
Parameters:visualizer (data_show) – the data show objectwhether to display during optimisation

Example usage:

This example loads in the CMU mocap database (http://mocap.cs.cmu.edu) subject number 35 motion number 01. It then plays it using the mocap_show visualize object.

data = GPy.util.datasets.cmu_mocap(subject='35', train_motions=['01'])
Y = data['Y']
Y[:, 0:3] = 0.   # Make figure walk in place
visualize = GPy.util.visualize.skeleton_show(Y[0, :], data['skel'])
GPy.util.visualize.data_play(Y, visualize)