Python Plots

Python distributed with Compose includes two plotting packages: Matplotlib and Plotly.

Matplotlib Plots

A Matplotlib plot can be an inline plot (default), use of one of the available matplotlib backends, or be displayed in a Compose undocked window using the custom Compose backend.

To open the Matplotlib plot in a Compose undocked window, select Preferences > PYTHON > Plot > Matplotlib figure > Undocked window.



Plotly Plots

A Plotly plot can be shown in the browser (default) or in a Compose undocked window.

To open the Plotly plot in a Compose undocked window, select Preferences > PYTHON > Plot > Plotly figure > Undocked window.

Python Plots in Compose Undocked Window

If the Undocked window option is selected for Matplotlib or Plotly, then new plots of this library are shown in an undocked window and in the Project Browser under Plots > python.

Example using Matplotlib:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10,50);
plt.plot(x, np.cos(x))
Example using Plotly:
import plotly.graph_objects as go
import numpy as np

x = np.linspace(0, 10,50);
fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=np.cos(x)))
fig.show()


New plots are visible in the Project Browser. The name of the library that was used to create the plot is added to the window name.

The context menu of the python plot Project Browser items contains the following actions:
  • 'Show': Shows the plot
  • 'Hide': Hides the plot
  • 'Delete': Deletes the plot
  • 'Rename': Renames the plot
  • 'Copy': Copies the plot’s image to clipboard
  • 'Save As Image': Saves the plot as an image. The following image file formats are supported for each library:
    • Matplotlib: .eps, .jpeg, .jpg, .pgf, .pdf, .png, .ps, .raw, .rgba, .svg, .svgz, .tif, .tiff
    • Plotly: .jpeg, .png

Comments

As per Matplotlib’s documentation, to export an image as .pgf “requires a recent LaTeX installation that includes the TikZ/PGF packages (such as TeXLive), preferably with XeLaTeX or LuaLaTeX installed. If either pdftocairo or ghostscript is present on your system, figures can optionally be saved to PNG images as well. The executables for all applications must be located on your PATH.”