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_location
str
Use valid location strings for matplotlib!
- legend_location
- 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.
- label
str
,optional
Legend entry for this line. If not given, no entry is used for this line.
- style
str
,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
- 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_size
int
,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_size
optional
Directly passed to matplotlib.pyplot.figure figsize parameter.
- sub_plot
tuple
,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.
- show{
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_widget
Bool
,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_size
tuple
,optional
Size of the main window
- plot_empty{
True
,False
},optional
If False and data is empty, it will not create a plot widget.
- only_widget
- 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:
- directory
str
oros.Pathlike
Directory the tikz file will be placed in
- file_name
str
,optional
Set a different file name to create. Default is self.name sluggified, by default None
- width
str
,optional
Width of the figure, by default ‘\textwidth’
- height
str
,optional
Height of the figure, by default None
- mark_repeat
int
,optional
Repeat the marks every x times, by default 1
- restrictbool,
optional
Turn on/off the restricted data feature from tikz, by default True
- nth
int
,optional
Plot only every nth line in the plot.
- mark_delta
int
,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
- fontsize
str
,optional
Latex fontsize, by default ‘normalsize’.
- line_width
str
,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.
- extension
str
,optional
Extension for the saved tikz file, if not given extension == “tex”.
- skip_every
callable()
,optional
Apply this callable to the lines in the plot and only plot what is returned, by default lambda x:x
- n_ticks_x
int
,optional
Number of ticks on x axis, by default None
- n_ticks_y
int
,optional
Number of ticks on y axis, by default None
- legend_location
str
,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>>}’
- directory
- 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:
- style
str
Style for plotting of the lines. Possible are: ‘color’, ‘bw’, ‘markers_color’, ‘markers’, ‘markers_lines’, ‘xtraction’, ‘xtraction_color’, ‘xtraction_interpolated’, ‘xtraction_interpolated_color’,
- style
- 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.