API¶
Expect for the templates, essentially all of the functionality is implemented in the Plot class.
Most get_* methods have been excluded below for the sake of brevity.
Plot¶
See documentation for the Plot class.
-
class
plotbridge.plot.Plot(name=None, template='gnuplot_2d', output_dir=None, overwrite=False)[source]¶ Container for a set of traces (“a plot”) and a template based system for generating a script that plots them.
Takes in global (i.e. per-plot) options together with a set of traces (data + per-trace options).
The inputs to plotbridge are (a) the data points and basic plot options from Python and (b) a template from a text file. Optionally, you can include a preprocess script (e.g. in Python) that massages the data before passing it to your plotting program.
-
__init__(name=None, template='gnuplot_2d', output_dir=None, overwrite=False)[source]¶ Create a plot object.
Parameters: - name – default will be ‘plot<n>’
- template – the template (e.g. ‘gnuplot_2d’) for generating the output, see the default_templates subdir for available built-in alternatives or provide a path to your own custom template.
- output_dir – where output subdir <name> should be created, default is current working dir.
- overwrite – If False, append a number to output_dir if it already exists.
-
add_trace(x, y=None, yerr=None, slowcoordinate=None, points=True, lines=False, skip=1, crop=0, title=None, pointtype=None, pointsize=None, linetype=None, linewidth=None, color=None, right=False, top=False, other=None, update=False, sort=None, x_plot_units=None, y_plot_units=None)[source]¶ Add a 1D trace to the plot (or rather a 2D parametric curve).
Parameters: - x,y – the x and y coordinates as two separate vectors of length N or as a Nx2 or 2xN matrix
- yerr – error bars for the ycoordinate
- slowcoordinate – second coordinate as a single scalar for the whole trace, used only in some templates (e.g. 2D color maps)
- points – draw points
- lines – connect points with lines
- skip – plot only every skip’th point
- crop – leave out crop points at each end
- title – label for this trace in a legend
- point/linetype – integer indicating the point/line style (see gnuplot pointtypes)
- point/linesize – size
- color – point/line color
- right – use the second y-axis (left = first y-axis)
- top – use the second x-axis (bottom = first x-axis)
- other – template-specific per-trace options (as a dictionary)
- update – regenerate the plot script?
- sort – if ‘x’ or ‘y’, sort the added points according to x or y first.
- x_plot_units – depracated, use set_x_units()
- y_plot_units – depracated, use set_y_units()
Returns: a unique identifier for the trace
-
get_name(path_friendly=False)[source]¶ Get the plot name.
Parameters: path_friendly – replace potentially problematic characters by “_”
-
get_ntraces(left=True, right=True)[source]¶ Number of traces. Count trace on left and/or right y-axis.
-
get_template()[source]¶ returns the full path to the .template file used for this plot as a triple (directory, filname, extension).
-
remove_trace(trace_id, update=False)[source]¶ Remove the specified trace.
Parameters: - trace_id – the identifier returned by
add_trace() - update – regenerate the plot script?
- trace_id – the identifier returned by
-
run(interactive=True)[source]¶ Execute the generated plot script.
Parameters: interactive – If true, execute the .interactive script instead.
-
set_export_format(val=None)[source]¶ Set the desired export format (png, pdf, etc.) for generating an image of the plot. Call
get_export_formats()to see which formats your template supports.
-
set_fontsize(val=None)[source]¶ Set the “base” font size for axis labels etc. Templates usually scale this to a smaller value for ticks etc.
-
set_other_options(val={})[source]¶ Pass other template-specific plot-level options (as a dictionary).
-
set_show_on_screen(val=True)[source]¶ Shown the output on screen (as opposed to only exporting to PNG/EPS/…).
Calling this does not automatically execute the plot script. (Do it using
run()or directly from a shell.)
-
update_trace(trace_id, x, y=None, yerr=None, update=False, sort=None)[source]¶ Update data points of the specified trace.
Parameters: - trace_id – the identifier returned by
add_trace() - x,y,yerr – see
add_trace() - update – regenerate the plot script?
- sort – sort the values according to ‘x’ or ‘y’
Note: Trace options cannot be updated after the initial
add_trace().- trace_id – the identifier returned by
-