plot module

Wrapper for nice plots with tikz, pyqtgraph and matplotlib.

Author:

Mario Krattenmacher | Mario.Krattenmacher@semimod.de Markus Mueller | Markus.Mueller3@tu-dresden.de

class DMT.core.plot.Plot(plot_name, style='mix', x_label=None, y_label=None, x_specifier=None, y_specifier=None, x_scale=None, y_scale=None, x_log=False, y_log=False, legend_location='upper right', num=None, divide_by_unit=False, caption=None)[source]

Bases: object

Class that represents plots with different plotting backends. Many convenience functions for device modeling are supported.

Attributes:
legend_locationstr

Use valid location strings for matplotlib!

add_data_set(x, y, label=None, style=None, **kwargs)[source]

Add y(x) to the plot

Each data set is a dict.

Parameters:
xarray_like

X data of this line.

yarray_like

Y data of this line.

labelstr, optional

Legend entry for this line. If not given, no entry is used for this line.

stylestr, optional

Matplotlib style descriptor for this line.

add_data_set_multiple_y(x, *y, label=None, style=None)[source]

Add y(x) to the plot

Each data set is a tuple with five entries, no need to create a dictionary, keeps it simple

Parameters:
xarray_like
*yarray-likes

multiple y arrays to plot versus x

labelstr or list(str), optional

Legend entry/ies

stylelist(str), optional

List of styles

list_pg_windows = [][source]
plot_py(show=True, font_size=None, allow_grid=False, tight_layout=True, figure_size=None, sub_plot=(1, 1, 1), repeated_labels=False, use_tex=True)[source]

Plots using matplotlib.pyplot, without IPython shell. If plot is displayed, the python session is halted.

Parameters:
show{True, False}, optional

Set to False if the plot should only be prepared, use show_py later to show it

font_sizeint, optional

Font size in the figure.

allow_grid{True, False}, optional

If True, a grid is activated.

tight_layout{True, False}, optional

Applies the tight_layout method from matplotlib on the plot. See: https://matplotlib.org/tutorials/intermediate/tight_layout_guide.html

figure_sizeoptional

Directly passed to matplotlib.pyplot.figure figsize parameter.

sub_plottuple, optional

Position of the subplot inside a figure.

repeated_labels{True, False}, optional

If True, repeated labels will be removed from the plot. E.g. when this plot holds 10 lines with the same label, only the first label is printed to the legend.

Notes

..todo: Interactive Mode.

plot_pyqtgraph(only_widget=False, show=True, figure_size=(800, 800), plot_empty=True)[source]

Plots the figure using PyQtGraph

Parameters:
only_widgetBool, False

If True, only a plot widget is returned that can be used in other Qt applications. If False, a full QApplication with layout is returned.

show{True, False}, optional

If True, the QtEventLoop is started at the end if the plotting.

figure_sizetuple, optional

Size of the main window

plot_empty{True, False}, optional

If False and data is empty, it will not create a plot widget.

qt_application = None[source]
remove_legend()[source]
save_png(directory)[source]

Saves the plot to a png

save_tikz(directory, file_name=None, width=None, height=None, mark_repeat=1, restrict=True, standalone=False, build=False, clean=False, fontsize='normalsize', line_width='very thick', svg=False, png=False, extension=None, nth=1, n_ticks_x=None, n_ticks_y=None, show_legend=True, legend_location=None, legend_to_name=None, legend_columns=4, mark_phase=False, **kwargs)[source]

Save plot in directory and return name of the tikz file.

The name of the tikz file will be the figure attribute self.num, if not given.

Parameters:
directorystr or os.Pathlike

Directory the tikz file will be placed in

file_namestr, optional

Set a different file name to create. Default is self.name sluggified, by default None

widthstr, optional

Width of the figure, by default ‘\textwidth’

heightstr, optional

Height of the figure, by default None

mark_repeatint, optional

Repeat the marks every x times, by default 1

restrictbool, optional

Turn on/off the restricted data feature from tikz, by default True

nthint, optional

Plot only every nth line in the plot.

mark_deltaint, optional

Start marks at this number of point, see https://tex.stackexchange.com/questions/239700/how-to-plot-mark-on-every-nth-point.

standalonebool, optional

Create standalone tikz figure, by default False

buildbool, optional

Build the latex file (only possible for standalone), by default False

cleanbool, optional

Remove all files except the rendered picture after build, by default False

fontsizestr, optional

Latex fontsize, by default ‘normalsize’.

line_widthstr, optional

Pgfplots line width, by default ‘very thick’.

svgbool, optional

Build the figure to svg (suited for FrameMaker), by default False

pngbool, optional

Build the figure to png.

extensionstr, optional

Extension for the saved tikz file, if not given extension == “tex”.

skip_everycallable(), optional

Apply this callable to the lines in the plot and only plot what is returned, by default lambda x:x

n_ticks_xint, optional

Number of ticks on x axis, by default None

n_ticks_yint, optional

Number of ticks on y axis, by default None

legend_locationstr, optional

Change legend location to something different, by default None

legend_to_name: str, optional

If this value is set to a name the legend is saved to a label with the provided name. It is not display inside the plot. Instead it can be printed anywhere in the document with ‘\rec{<<name>>}’

Returns:
str

file name including path

Raises:
IOError

Raised if non-standalone figures are tried to build

set_cycler(style)[source]

Sets the line cycler. Possible styles are defined in the top of this file for convenience.

Parameters:
stylestr

Style for plotting of the lines. Possible are: ‘color’, ‘bw’, ‘markers_color’, ‘markers’, ‘markers_lines’, ‘xtraction’, ‘xtraction_color’, ‘xtraction_interpolated’, ‘xtraction_interpolated_color’,

set_x_label(x_label=None, x_specifier=None, x_scale=None)[source]

Set the x label. Either using directly a string or a specifier.

Parameters:
x_labelstr
x_specifierSpecifierStr
x_scalefloat

If given, self.x_scale is overwritten with this value.

Raises:
IOError

If neither x_label nor x_specifier were given.

set_y_label(y_label=None, y_specifier=None, y_scale=None)[source]

Set the y label. Either using directly a string or a specifier.

Parameters:
y_labelstr
y_specifierSpecifierStr
y_scalefloat

If given, self.y_scale is overwritten with this value.

Raises:
IOError

If neither y_label nor y_specifier were given.

show_py()[source]

Calls .show on the matplotlib figure

show_pyqtgraph()[source]

Reshows the PyQtGraph main window and startes the Qt event loop

DMT.core.plot.save_or_show(plts, show=True, location=None, **kwargs)[source]

Convenience function for either showing or saving an array of DMT plots.

Parameters:
plts[Plot]

An array of plots

showBool, True

If true, the plots will be opened in the interactive Matplotlib editor, else they will be saved as specified by the other args.

locationos.path

Here the plots will be saved

kwargs{}

Additional arguments that are passed to the save_tikz routine.