This guide is for versions 1.0.0rc.2+ (Release Candidate)
Static class to assist in the use of the plotly library.
For color management, see the separate class "Colors"
| name | arguments | returns |
|---|---|---|
| plot_curves | x, y, title="", range_x=None, x_label="", y_label="", curve_labels=None, legend_title=None, colors=None, show=False | pgo.Figure |
Plot one or more 2D curves. If your data is a in a Pandas dataframe, consider using plot_pandas()
:param x: A Numpy array, with the (common) x-axis values
:param y: Either a Numpy array, or a list/tuple of them, with the y-axis values of the curve(s)
:param title: [OPTIONAL] Title to use for the overall plot
:param range_x: [OPTIONAL] list of the form [t_start, t_end], to initially only show a part of the timeline.
Note: it's still possible to zoom out, and see the excluded portion
:param x_label: [OPTIONAL] Caption to use for the x-axis
:param y_label: [OPTIONAL] Caption to use for the y-axis
:param curve_labels:[OPTIONAL] String, or list of strings.
Label(s) to use for the various curves in the legend and in the hover boxes.
If missing, and there's only 1 curve, the legend box won't be shown
:param legend_title:[OPTIONAL] String to show at the top of the legend box.
Ignored if curve_labels wasn't set.
If not provided, and the legend box is shown, it will appear as "variable"
:param colors: [OPTIONAL] Either a single color (string with standard plotly CSS name, such as "red"),
or list of names to use, in the same order as the y variables; if None, then use the hardwired defaults
:param show: If True, the plot will be shown
Note: in JupyterLab, simply returning a plot object (without assigning it to a variable)
leads to it being automatically shown
:return: A plotly "Figure" object
|
||
| name | arguments | returns |
|---|---|---|
| plot_pandas | df :pd.DataFrame, x_var="SYSTEM TIME", fields=None, colors=None, title=None, title_prefix=None, range_x=None, range_y=None, x_label=None, y_label="Y", legend_header="Plot", vertical_lines_to_add=None, show_intervals=False, smoothed=False, show=False | pgo.Figure |
Using plotly, draw line plots from the values in the given dataframe.
One column supplies the values for the x-axis,
and one or more other columns supply the y-axis values for one or more line plots.
Note: if this plot is to be later combined with others, use PlotlyHelper.combine_plots()
:param df: Pandas dataframe with the data for the plot
:param x_var: Name of column with the independent variable for the x-axis
:param fields: Name, or list of names, of the dataframe columns whose values are to be plotted;
if a list is passed, also display a figure legend;
if None, then display all columns except the one that was declared as the independent variable
:param colors: [OPTIONAL] Either a single color (string with standard plotly name, such as "red"),
or list of names to use, in order; some of the entries may be None.
If None, then the hardwired default colors are used
:param title: [OPTIONAL] Title for the plot
:param title_prefix: [OPTIONAL] String to prefix (automatically followed by "
|
||
| name | arguments | returns |
|---|---|---|
| combine_plots | fig_list :Union[list, tuple], title="", x_label=None, y_label=None, xrange=None, legend_title=None, curve_labels=None, show=False | pgo.Figure |
Combine together several existing plotly plots into a single one (with combined axes)
EXAMPLE:
from life123 import PlotlyHelper
p1 = PlotlyHelper.plot_pandas(various args, show=False)
p2 = PlotlyHelper.plot_pandas(various args, show=False)
PlotlyHelper.combine_plots([p1, p2], other optional args)
:param fig_list: List or tuple of plotly "Figure" objects (as returned by several functions)
:param title: [OPTIONAL] The title to use for the overall plot
:param x_label: [OPTIONAL] Caption to use for the x-axis; if not specified, use that of the 1st plot
:param y_label: [OPTIONAL] Caption to use for the y-axis; if not specified, use that of the 1st plot
:param xrange: [OPTIONAL] list of the form [t_start, t_end], to initially only show a part of the timeline.
Note: it's still possible to zoom out, and see the excluded portion
:param legend_title:[OPTIONAL] String to show at the top of the legend box
:param curve_labels:[OPTIONAL] List of labels to use for the various curves in the legend
and in the hover boxes; if not specified, use the titles of the individual plots
:param show: If True, the plot will be shown
Note: on JupyterLab, simply returning a plot object (without assigning it to a variable)
leads to it being automatically shown
:return: A plotly "Figure" object for the combined plot
|
||
| name | arguments | returns |
|---|---|---|
| combine_in_vertical_grid | fig1, fig2, title1 :str, title2 :str, title_combined :str, height=900 | pgo.Figure |
Combine into a vertical grid 2 plotly graph objects (now treated as subplots)
:param fig1:
:param fig2:
:param title1:
:param title2:
:param title_combined:
:param height [OPTIONAL] The overall height of the combined plots
:return: A combined plot (a plotly "figure" object)
|
||
| name | arguments | returns |
|---|---|---|
| heatmap_grid | array_list :list, labels :[str], title ="Grid of Heatmaps", height=None, colors=None, z_name="z", max_n_cols=4, cartesian=True | pgo.Figure |
Prepare and return a Plotly Figure object containing a grid of heatmaps (up to a max of 12)
:param array_list: List of 2-D Numpy arrays, up to a maximum of 12,
containing the data for each of the heatmaps
:param labels: List of labels for each of the heatmaps; its length must match that of the data
:param title: [OPTIONAL] Overall title to show at the top of the grid of heatmaps
:param height: [OPTIONAL] Height of the overall grid of heatmaps
:param colors: [OPTIONAL] List of CSS color names for each of the heatmaps.
If provided, its length must match that of the data; otherwise, default colors are used
:param z_name: [OPTIONAL] Name of the quantity being visualized in the heatmaps; e.g. "Conc." or "Temp."
:param max_n_cols: [OPTIONAL] The maximum number of columns to use in the grip (at most 4)
:param cartesian: If True (default) a Cartesian grid coordinate is used, with y-bin numbers increasing up
:return: A Plotly "Figure" object
|
||