PlotZ python API

This is the python API to PlotZ.

PlotZ is a system to produce TikZ-based plots destined to be seamlessly included in a LaTeX document.

class plotz.Plot(output)[source]

Master object to create a PlotZ figure.

This object is supposed to be used in a with statement:

with Plot("myname") as p:
    p.plot(...)

    # the plot is actually generated at the end of the block
grid()[source]

Draw a grid at axes ticks

grid_x = None

True if vertical grid lines should be drawn

grid_y = None

True id horizontal grid lines should be drawn

hist(data, col=0, title=None)[source]

Plot a histogram

Parameters:
  • data – data generator (see Function and DataFile)
  • col (int) – column index (if data has multiple columns)
  • title (str) – line title
Returns:

the drawn Bar, which can be modifed afterwards as needed.

legend = None

Plot Legend

output = None

Basename of the output figure

Plotz will generate two files
  • <output>.tex: the actual PlotZ figure, which you can include in any LaTeX document using the plotz command.
  • <output>.pdf: a rendered pdf version of the figure.
plot(data, col=(0, 1), title=None)[source]

Plot a curve

Parameters:
  • data – data generator (see Function and DataFile)
  • col (tuple) – tuple of column indices to plot
  • title (str) – line title
Returns:

the drawn Line, which can be modifed afterwards as needed.

scale = None

Plot scale.

This is a convenient way to adjust the default size of the plot without affecting its aspect ratio. Both size_x and size_y are multiplied by scale to determine the default plot size.

size_x = None

Plot width

This defines the default width of the plotting area (i.e excluding axis labels, title, legend…) It is used when producing the pdf output, and as a default size when including the plot in a LaTeX document. This size can be changed in LaTeX using \plotz[width=...]{}

The default aspect ratio of the plotting area is 4:3

size_y = None

Plot height (see size_x for more details)

style = None

Plot Style

title = None

Plot title

x = None

x Axis

y = None

y Axis

class plotz.Axis(orientation)[source]

Plot axis

This object stores everything related to plot axes: range, position, position of ticks…

label = None

Axis label

label_rotate = None

True if the label should be rotated

label_shift = None

Space between the axis and the label

static linear(x)[source]

Linear scale

static logarithmic(x)[source]

Logarithmic scale

max = None

Maximum axis value

This value is computed automatically when plotting data, but can be changed manually if necessary.

min = None

Minimum axis value. (see max for details)

pos = None

Position of the axis with respect to the other axis.

By default, the position will be set to the minimum value of the other axis. In other words, by default, the x and y axes are respectively drawn on the bottom and left part of the plotting area.

scale

Axis scalelinear or logarithmic

tick_anchor = None

Anchor of tick labels

tick_format = None

Function called to format tick labels.

The default behaviour is to label tick as \(10^x\) in logarithmic scale, and to pretty-print values in linear scale.

tick_rotate = None

Rotate tick labels by this amount (in degrees)

ticks = None

List of axis ticks, in one of three forms

  1. dx
  2. [x1, x2, x3, …]
  3. [(x1, label1), (x2, label2), …]

Detailed explanation:

  1. Tick positions range from min to max by increments of dx. Tick labels are computed by tick_format.
  2. Ticks are placed at positions x1, x2, x3… Labels are computed by tick_format.
  3. Ticks are placed at positions x1, x2, x3… Labels are defined by label1, label2, label3
class plotz.Legend[source]

Plot legend

__call__(position, anchor=None)[source]

Helper function to set the legend position in one call.

Parameters:
anchor = None

Anchor relatively to which the legend is positioned.

This defines which part of the legend is positioned where defined by position. This should be a string denoting a TikZ anchor (such as “north east”, meaning that the top left corner of the legend is to be positioned where defined by position).

margin = None

Margin around the anchor (in em).

position = None

Position of the legend in the plot.

If this is a string (such as “north east”), it is taken to be a TikZ anchor in the plotting area.

Otherwise, position should be a tuple of coordinates.

show = None

True if the legend should be drawn on the plot

class plotz.Style[source]

This object is responsible for storing all settings related to the styling of the plot: colors, line patterns, markers…

color = None

List of colors used in the plot. This might be more easily set using colormap()

colormap(name=None)[source]

Setup a colormap.

Predefined colormaps come from colorbrewer2.org:

default
8-color map with qualitatively varying colors (qualitative, set1)
dark
8-color map with qualitatively varying colors in darker tones (qualitative, dark2)
paired
8-color map with paired colors (qualitative, paired)
spectralN (for N=4..8)
N-color map with diverging colors (diverging, spectral)
monochrome
map with all colors set to black
dashed(activate=True)[source]

Set the plot up to use dashed patterns for lines.

This is useful in combination with the “monochrome” colormap()

marker = None

List of markers used in the plot.

pattern = None

List of dash/dot patterns used in the plot.

By default, all lines are solid.

thickness = None

List of TikZ line thicknesses used in the plot

By default, all lines are very thick.

class plotz.Line(plot)[source]

A line in the plot.

Plotted lines are created by Plot.plot(), but they can be altered afterwards.

color = None

Index of the line color in the Style.color list.

line = None

True if the line should be drawn.

markers = None

Index of the point markers in the Style.marker list.

markers_filter = None

Filter determining when markers actually get drawn.

See plotz.utils.Markers for a list of built-in filters.

pattern = None

Index of the line dash/dot pattern in the Style.pattern list.

style(properties)[source]

Style a newly-created line

Args:

dict properties: a dictionary containing style attributes (see
py:class:Line for a list of all supported attributes). As a special case, if markers is set to True, it will be replaced by the next available marker index.
thickness = None

Index of the line thickness in the Style.thickness list.

title = None

Title of the line.

If set, this is what goes in the plot legend.

class plotz.Function(fun, samples=100, range=None)[source]

Data generator for python functions

Parameters:
  • fun (function) – python function
  • samples (int) – number of sampled points
  • range (tuple) – range of the data
plotz.DataFile(filename, sep=<_sre.SRE_Pattern object>, comment='#')[source]

Data generator for an ASCII datafile

Parameters:
  • filename (str) – path to the data file
  • sep (str or re) – delimiter for columns
  • comment (str) – string indicating the beginning of a comment line