Installation
SymPy Plotting Backends can be installed with pip or conda. By default, only basic plotting with Matplotlib will be installed:
pip install sympy_plot_backends
Or:
conda install sympy_plot_backends
To install the complete requirements in order to get interactive plots, bokeh, plotly, k3d, vtk, execute the following command:
pip install sympy_plot_backends[all]
Or:
conda install -c anaconda scipy notebook colorcet
conda install -c conda-forge ipympl panel k3d vtk msgpack-python
conda install -c bokeh ipywidgets_bokeh
conda install -c plotly plotly
Verify the installation
After installation, it is best to verify that the freshly-installed SymPy Plotting Backends work. To do this, start up Python and import the necessary functionalities, as shown below. To improve typing experience, the actual name of the module has been set to spb:
$ python
>>> from sympy import *
>>> from spb import *
From here, execute some simple statements like the ones below:
>>> x = Symbol('x')
>>> plot(sin(x), cos(x))
If the additional requirements have been installed, try the following:
from sympy import *
from spb import *
x, a, b, c = symbols("x, a, b, c")
plot(
(cos(a * x + b) * exp(-c * x), "oscillator"),
(exp(-c * x), "upper limit", {"line_dash": "dotted"}),
(-exp(-c * x), "lower limit", {"line_dash": "dotted"}),
(x, 0, 2 * pi),
params={
a: (1, 0, 10), # frequency
b: (0, 0, 2 * pi), # phase
c: (0.25, 0, 1) # damping
},
ylim=(-1.25, 1.25),
backend=BB,
servable=True
)
It is also the perfect time to verify that K3D-Jupyter is working:
launch
jupyter notebook
.open a notebook.
run the following code:
from sympy import * from spb import * var("x, y") plot3d(cos(x**2 + y**2), (x, -2, 2), (y, -2, 2), backend=KB)
If no figure is visible in the output cell, follow this procedure:
Save the Notebook.
Close Jupyter server.
Run the following commands, which are going to install the Jupyter extension for K3D:
jupyter nbextension install --user --py k3d
jupyter nbextension enable --user --py k3d
Restart
jupyter notebook
Open the previous notebook and execute the plot command.
Refer to the Tutorials for a starter guide on using the plotting backends or to the Functions to visualize the output of some of the plotting functions.
Installing Mayavi
This plotting module comes with MayaviBackend
. Mayavi is a 3D plotting
library which can be used on any Python interpreter.
However, it is not the easiest to install.
If you are interested in using it, please follow Mayavi’s installation instruction.
About Matplotlib
If you are doing development work on this module, Matplotlib 3.4.2 is required for tests to pass!