TBTK
Need a break? Support the development by playing Polarity Puzzles
Plotting

See more details about the Plotter in the API

Plotting with Matplotlib as backend

If Python, Matplotlib, and NumPy is installed, TBTK allows for data to be plotted immediately from C++. The Plotter exists in the namespace TBTK::Visualization::MatPlotLib and below we assume that the following lines have been added at the top of the code.

using namespace TBTK;
using namespace Visualization::MatPlotLib;

Setting up and configuring a Plotter

We begin by listing some of the most common commands needed for setting up and configuring the Plotter.

Create a Plotter

Plotter plotter;

Note: All Plotter objects use the same matplotlib instance as backend and can therefore interfere with each other when used simultaneously.

Setting the canvas size

plotter.setSize(width, height);

Clear the canvas

plotter.clear();

Save the canvas to file

plotter.save("FigureName.png");

Set axis bounds
By default, the axes automatically scale to contain the data. It is possible to fix the axis bounds with the following calls.

plotter.setBoundsX(-1, 1);
plotter.setBoundsY(0, 10);

These calls can also be combined into a single call.

plotter.setBounds(-1, 1, 0, 10);

Examples

We here provide a few examples of how the Plotter can be used. For more examples, including how to plot Properties, see the API.

1D data
If data is an std::vector<double> or a one-dimensional Array, it can be plotted using

plotter.plot(data);

By default, the x-axis will run from 0 to the number of data points minus one. If domain has the same type and size as data and contains custom values for the x-axis, we can also use

plotter.plot(domain, data);

2D data
If data is an std::vector<std::vector<double>> or a two-dimensional Array, it can be plotted using

plotter.plot(data);