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_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: Returns: the drawn
Bar
, which can be modifed afterwards as needed.
-
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 theplotz
command.<output>.pdf
: a rendered pdf version of the figure.
-
plot
(data, col=(0, 1), title=None)[source]¶ Plot a curve
Parameters: 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
andsize_y
are multiplied byscale
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
-
title
= None¶ Plot title
-
-
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
-
max
= None¶ Maximum axis value
This value is computed automatically when plotting data, but can be changed manually if necessary.
-
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 scale –
linear
orlogarithmic
-
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
- dx
- [x1, x2, x3, …]
- [(x1, label1), (x2, label2), …]
Detailed explanation:
- Tick positions range from
min
tomax
by increments of dx. Tick labels are computed bytick_format
. - Ticks are placed at positions x1, x2, x3… Labels are
computed by
tick_format
. - 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 byposition
).
-
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.
-