A small Python library for drawing beautiful plots on top of matplotlib.
Plotter wraps common plotting tasks in small drawable objects with sensible defaults.
The library is still matplotlib-based, so it works best when the user is already somewhat
familiar with the underlying plotting model.
The current design revolves around:
- a
Canvasobject, which owns the figure and axes and acts as a context manager; - drawable objects such as
ScatterPlot,LinePlot,BarChart,Hist,Hist2D, andImage; - optional JSON text files used to populate titles, axis labels, and legend labels.
On Unix-like systems:
-
Clone the repository.
-
Move into the project directory.
-
Install the package:
pip install . -
Import it in Python:
import plotter
Call plotter.setup_workspace() once in the directory where you want to work.
This creates the files and folders used by the library:
plotter
├── img
├── log
│ └── plotter.log
├── text
│ └── text_example.json
└── utils
├── blueprint.txt
├── info
├── log_config.json
└── style.mplstyle
These files have the following purposes:
plotter/img/stores saved figures.plotter/log/stores log output.plotter/text/stores JSON files with plot titles, axis labels, and legend labels. A subplot entry can includescatter_plots,line_plots,bar_charts,histograms,histograms_2d, andimages.plotter/utils/stores bundled helper assets and configuration files.
Canvas is a context manager. That means the figure lifecycle is handled automatically:
when the with block exits, Plotter finalizes the legend, saves the figure if requested, and
shows or closes it depending on the canvas configuration.
import numpy as np
import plotter as p
def f(x):
return x**2
# datasets to plot
x = np.linspace(-5, 5, num=50)
y = x**2
y_err = np.full(50, 0.5)
x_err = np.full(50, 0.2)
categories = np.array([0.0, 1.0, 2.0])
heights = np.array([2.0, 4.0, 3.0])
with p.Canvas("example.json", rows_cols=(1, 2), show=False) as canvas:
canvas.setup(0)
canvas.setup(1)
p.ScatterPlot(x, y, y_err, x_err).draw(canvas, label="data")
p.LinePlot(x, f, wider=(0.01, 0.01)).draw(canvas, label=r"$f(x)=x^2$")
p.BarChart(categories, heights).draw(canvas, plot_n=1, label="counts")ScatterPlot: scatter plots with optional x/y error bars.LinePlot: function plots or explicit x/y line plots.BarChart: bar charts with optional y-error bars.Hist: one-dimensional histograms.Hist2D: two-dimensional histograms with colorbars.Image: grayscale or RGB(A) image rendering.
All drawable classes inherit from Drawable and implement a draw(canvas, ...) method.
See the LICENSE file for license rights and limitations.

