MatplotlibBackend

class spb.backends.matplotlib.MatplotlibBackend(*args, **kwargs)[source]

A backend for plotting SymPy’s symbolic expressions using Matplotlib.

Parameters:
aspect(float, float) or str, optional

Set the aspect ratio of a 2D plot. Possible values:

  • "auto": Matplotlib will fit the plot in the vibile area.

  • "equal": sets equal spacing.

  • tuple containing 2 float numbers, from which the aspect ratio is computed. This only works for 2D plots.

axis_center(float, float) or str or None, optional

Set the location of the intersection between the horizontal and vertical axis in a 2D plot. It can be:

  • None: traditional layout, with the horizontal axis fixed on the bottom and the vertical axis fixed on the left. This is the default value.

  • a tuple (x, y) specifying the exact intersection point.

  • 'center': center of the current plot area.

  • 'auto': the intersection point is automatically computed.

cameradict, optional

A dictionary of keyword arguments that will be passed to the Axes3D.view_init method. Refer to [9] for more information.

rendering_kwdict, optional

A dictionary of keywords/values which is passed to Matplotlib’s plot functions to customize the appearance of lines, surfaces, images, contours, quivers, streamlines… To learn more about customization:

  • Refer to [1] to customize contour plots.

  • Refer to [2] to customize image plots.

  • Refer to [3] to customize solid line plots.

  • Refer to [4] to customize colormap-based line plots.

  • Refer to [5] to customize quiver plots.

  • Refer to [6] to customize surface plots.

  • Refer to [7] to customize stramline plots.

  • Refer to [8] to customize 3D scatter plots.

  • Refer to [10] to customize 2D arrows.

axisboolean, optional

Turns on/off the axis visibility (and associated tick labels). Default to True (axis are visible).

update_eventbool, optional

If True, it binds pan/zoom events in order to automatically compute new data as the user interact with the plot. Default to False.

annotationslist, optional

A list of dictionaries specifying the type of annotation required. The keys in the dictionary should be equivalent to the arguments of the matplotlib.axes.Axes.annotate method. This feature is experimental. It might get removed in the future.

markerslist, optional

A list of dictionaries specifying the type the markers required. The keys in the dictionary should be equivalent to the arguments of the matplotlib.pyplot.plot() function along with the marker related keyworded arguments. This feature is experimental. It might get removed in the future.

rectangleslist, optional

A list of dictionaries specifying the dimensions of the rectangles to be plotted. The keys in the dictionary should be equivalent to the arguments of the matplotlib.patches.Rectangle class. This feature is experimental. It might get removed in the future.

filldict, optional

A dictionary specifying the type of color filling required in the plot. The keys in the dictionary should be equivalent to the arguments of the matplotlib.axes.Axes.fill_between method. This feature is experimental. It might get removed in the future.

See also

Plot, PlotlyBackend, BokehBackend, K3DBackend

References

MatplotlibBackend.fig

Returns the figure.

MatplotlibBackend.ax

Returns the axis used for the plot.

Notes

To get the axis of a colorbar, index p.fig.axes where p is a plot object. p.fig.axes[0] corresponds to p.ax.

spb.backends.matplotlib.MatplotlibBackend.append(self, arg)

Adds an element from a plot’s series to an existing plot.

Parameters:
argBaseSeries

An instance of BaseSeries which will be used to generate the numerical data.

See also

extend

Examples

Consider two Plot objects, p1 and p2. To add the second plot’s first series object to the first, use the append method, like so:

>>> from sympy import symbols
>>> from spb import plot
>>> x = symbols('x')
>>> p1 = plot(x*x, show=False)
>>> p2 = plot(x, show=False)
>>> p1.append(p2[0])
>>> p1
Plot object containing:
[0]: cartesian line: x**2 for x over (-10.0, 10.0)
[1]: cartesian line: x for x over (-10.0, 10.0)
>>> p1.show()

(Source code, png)

../../_images/matplotlib-1.png
spb.backends.matplotlib.MatplotlibBackend.close(self)

Close the current plot.

spb.backends.matplotlib.MatplotlibBackend.extend(self, arg)

Adds all series from another plot.

Parameters:
argPlot or sequence of BaseSeries

See also

append

Examples

Consider two Plot objects, p1 and p2. To add the second plot to the first, use the extend method, like so:

>>> from sympy import symbols
>>> from spb import plot
>>> x = symbols('x')
>>> p1 = plot(x**2, show=False)
>>> p2 = plot(x, -x, show=False)
>>> p1.extend(p2)
>>> p1
Plot object containing:
[0]: cartesian line: x**2 for x over (-10.0, 10.0)
[1]: cartesian line: x for x over (-10.0, 10.0)
[2]: cartesian line: -x for x over (-10.0, 10.0)
>>> p1.show()

(Source code, png)

../../_images/matplotlib-2.png
spb.backends.matplotlib.MatplotlibBackend.save(self, path, **kwargs)

Save the current plot at the specified location.

Refer to [11] to visualize all the available keyword arguments.

References

spb.backends.matplotlib.MatplotlibBackend.show(self, **kwargs)

Display the current plot.

Parameters:
**kwargsdict

Keyword arguments to be passed to plt.show().

spb.backends.matplotlib.MatplotlibBackend.update_interactive(self, params)

Implement the logic to update the data generated by interactive-widget plots.

Parameters:
paramsdict

Map parameter (symbols) to numeric values.