Plotting Tools¶
Plotshop Package Content¶
Module plotshop.plot_style¶
Helper functions to make the most awesome* plots out there.
- please feel free to add more stuff
-
class
plotshop.plot_style.
MarkerList
[source]¶ Create a list of predefined markers
-
class
plotshop.plot_style.
OOMFormatter
(order=0, fformat='%1.1f', offset=True, mathText=True)[source]¶ Order of Magnitude Formatter.
To set a fixed order of magnitude and fixed significant numbers. As seen on: https://stackoverflow.com/a/42658124/5609590
See: set_sci_magnitude
-
plotshop.plot_style.
change_color_brightness
(color, amount=0.5)[source]¶ Lightens the given color by multiplying (1-luminosity) by the given amount. Input can be matplotlib color string, hex string, or RGB tuple. An amount of 1 equals to no change. 0 is very bright (white) and 2 is very dark. By Ian Hincks Source: https://stackoverflow.com/questions/37765197/darken-or-lighten-a-color-in-matplotlib
-
plotshop.plot_style.
change_ebar_alpha_for_axes
(ax, alpha)[source]¶ Wrapper for change_ebar_alpha_for_line
-
plotshop.plot_style.
change_ebar_alpha_for_line
(ebar, alpha)[source]¶ loop through bars (ebar[1]) and caps (ebar[2]) and set the alpha value
-
plotshop.plot_style.
get_annotation
(ax=None, by_reference=False)[source]¶ Returns the annotation set by set_annotation()
Parameters: - ax -- Axes to get annotation from. If ‘None’ takes current Axes. (Default: None)
- by_reference (bool) -- If true returns the reference to the annotation, otherwise the text as string. (Default: False)
-
plotshop.plot_style.
get_ip_positions
(path)[source]¶ Returns a dict of IP positions from tfs-file of path.
Parameters: path (str) -- Path to the tfs-file containing IP-positions
-
plotshop.plot_style.
get_legend_ncols
(labels, max_length=78)[source]¶ Calulate the number of columns in legend dynamically
-
plotshop.plot_style.
get_name
(fig_or_ax=None)[source]¶ Returns the name of the figure or axes
Parameters: fig_or_ax -- Figure or Axes to to use. If ‘None’ takes current figure. (Default: None)
-
plotshop.plot_style.
make_top_legend
(ax, ncol, frame=False, handles=None, labels=None)[source]¶ Create a legend on top of the plot.
-
plotshop.plot_style.
set_annotation
(text, ax=None)[source]¶ Writes an annotation on the top right of the axes
Parameters: - text -- The annotation
- ax -- Axes to set annotation on. If ‘None’ takes current Axes. (Default: None)
-
plotshop.plot_style.
set_name
(name, fig_or_ax=None)[source]¶ Sets the name of the figure or axes
Parameters: - name (str) -- Sting to set as name.
- fig_or_ax -- Figure or Axes to to use. If ‘None’ takes current figure. (Default: None)
-
plotshop.plot_style.
set_sci_magnitude
(ax, axis='both', order=0, fformat='%1.1f', offset=True, math_text=True)[source]¶ Uses the OMMFormatter to set the scientific limits on axes.
Parameters: - ax -- Plotting axes
- axis (str) -- “x”, “y” or “both”
- order (int) -- Magnitude Order
- fformat (str) -- Format to use
- offset (bool) -- Formatter offset
- math_text (bool) -- Whether to use mathText
-
plotshop.plot_style.
set_style
(style='standard', manual=None)[source]¶ Sets the style for all following plots.
Parameters: - style -- Choose Style, either ‘standard’ or ‘presentation’
- manual -- Dict of manual parameters to update. Convention: “REMOVE_ENTRY” removes entry
-
plotshop.plot_style.
set_xLimits
(accel, ax=None)[source]¶ Sets the x-limits to the regularly used ones
Parameters: - accel -- Name of the Accelerator
- ax -- Axes to put the label on (default: gca())
-
plotshop.plot_style.
set_xaxis_label
(ax=None)[source]¶ Sets the standard x-axis label
Parameters: ax -- Axes to put the label on (default: gca())
-
plotshop.plot_style.
set_yaxis_label
(param, plane, ax=None, delta=False, chromcoup=False)[source]¶ Set y-axis labels.
Parameters: - param -- One of the ylabels above
- plane -- Usually x or y, but can be any string actually to be placed into the label ({0})
- ax -- Axes to put the label on (default: gca())
- delta -- If True adds a Delta before the label (default: False)
-
plotshop.plot_style.
show_ir
(ip_dict, ax=None, mode='inside')[source]¶ Plots the interaction regions into the background of the plot.
Parameters: - ip_dict -- dict, dataframe or series containing “IPLABEL” : IP_POSITION
- ax -- Axes to put the irs on (default: gca())
- mode -- ‘inside’, ‘outside’ + ‘nolines’ or just ‘lines’
Module plotshop.plot_tfs¶
Wrapper to easily plot tfs-files. With entrypoint functionality.
-
plotshop.plot_tfs.
plot
(*args, **kwargs)[source]¶ Plots data from different twiss-input files into one plot.
Keyword Arguments: - Required --
- files (basestring) -- Twiss files to plot Flags: --files
- y_cols (basestring) -- List of column names to plot (e.g. BETX, BETY) Flags: [‘-y’, ‘--y_cols’]
- Optional --
- auto_scale (float) -- Scales the plot, so that this percentage of points is inside the picture. Flags: --autoscale
- change_marker -- Changes marker for each line in the plot.
Flags: --changemarker
Action:
store_true
- e_cols (basestring) -- List of parameters to get error values from. Flags: [‘-e’, ‘--e_cols’]
- labels (basestring) -- Y-Lables for the plots, default: y_col. Flags: --labels
- no_legend -- Deactivates the legend.
Flags: --nolegend
Action:
store_true
- no_show -- Suppresses opening plotting windows.
Flags: --noshow
Action:
store_true
- output (basestring) -- Base-Name of the output files. _’y_col’.pdf will be attached. Flags: --output
- figure_per_file (bool) -- Plots all colimns into one figure. (Works only with one file so far).
Flags: --figperfile
Action:
store_true
- file_labels (basestring) -- Names for the sources for the plots, default: filenames. Flags: --file_labels
- x_cols (basestring) -- List of column names to use as x-values. Flags: [‘-x’, ‘--x_cols’]
- xy (bool) -- Plots X and Y for the give parameters into one figure (two axes).
Flags: --xy
Action:
store_true
Module plotshop.post_processing¶
Functions for plot post-processing.
-
plotshop.post_processing.
get_errorbar_data
(ax)[source]¶ Extract data from all errorbars in axes.
Parameters: ax -- axes handle to axes to extract data from. Returns: List of dictionaries of extracted data with keys as follows: label: Line labelx: x-position data of the pointsy: y-position data of the pointsxerr: tupel with arrays corresponding to lower and upper x-error valuesyerr: tupel with arrays corresponding to lower and upper y-error valueswith: Linewidthstyle: Linestylecolor: LinecolorFor
"_nolegend_"
entries an index is added to avoid collision.See also
get_line_data()
-
plotshop.post_processing.
get_line_data
(ax)[source]¶ Extract data from all lines in axes.
Parameters: ax -- axes handle to axes to extract data from. Returns: List of dictionaries of extracted data with keys as follows: label: Line labelx: x-position data of the pointsy: y-position data of the pointswith: Linewidthstyle: Linestylecolor: LinecolorIf a line is found to be an error-bar-line it is ignored! For
"_nolegend_"
entries an index is added to avoid collision.See also
get_errorbar_data()
Figure Editor¶
Module plotshop.fig_editor.main_window: QT-based Figure Editor¶
This is an extended figure editor based on the PyQT5 backend of matplotlib.
- Functionality:
- easily plot from tfs files
- change plot attributes by douple click on element
- change plot attributes via icon in navigation bar
- drag text around
- move the legend to predefined positions
- Planned:
- copy paste between plots
- have a “draggable” switch for text objects
- add texts to options_figure to find invisible texts again
WARNING: Pre-Alpha version.