plot: create reproducible plots from tables
Code author: Ueli Sauter, Peter Kraus
The function dgpost.utils.plot.plot()
processes the below specification
in order to generate a plot:
- pydantic model dgbowl_schemas.dgpost.recipe.Plot
Plot data from a single table.
Show JSON schema
{ "title": "Plot", "description": "Plot data from a single table.", "type": "object", "properties": { "table": { "title": "Table", "type": "string" }, "nrows": { "default": 1, "title": "Nrows", "type": "integer" }, "ncols": { "default": 1, "title": "Ncols", "type": "integer" }, "fig_args": { "anyOf": [ { "type": "object" }, { "type": "null" } ], "default": null, "title": "Fig Args" }, "ax_args": { "items": { "$ref": "#/$defs/AxArgs" }, "title": "Ax Args", "type": "array" }, "style": { "anyOf": [ { "type": "object" }, { "type": "null" } ], "default": null, "title": "Style" }, "save": { "anyOf": [ { "$ref": "#/$defs/PlotSave" }, { "type": "null" } ], "default": null } }, "$defs": { "AxArgs": { "additionalProperties": true, "properties": { "cols": { "anyOf": [ { "maxItems": 2, "minItems": 2, "prefixItems": [ { "type": "integer" }, { "type": "integer" } ], "type": "array" }, { "type": "null" } ], "default": null, "title": "Cols" }, "rows": { "anyOf": [ { "maxItems": 2, "minItems": 2, "prefixItems": [ { "type": "integer" }, { "type": "integer" } ], "type": "array" }, { "type": "null" } ], "default": null, "title": "Rows" }, "series": { "items": { "$ref": "#/$defs/Series" }, "title": "Series", "type": "array" }, "methods": { "anyOf": [ { "type": "object" }, { "type": "null" } ], "default": null, "title": "Methods" }, "legend": { "default": false, "title": "Legend", "type": "boolean" } }, "required": [ "series" ], "title": "AxArgs", "type": "object" }, "PlotSave": { "additionalProperties": true, "properties": { "as": { "title": "As", "type": "string" }, "tight_layout": { "anyOf": [ { "type": "object" }, { "type": "null" } ], "default": null, "title": "Tight Layout" } }, "required": [ "as" ], "title": "PlotSave", "type": "object" }, "Series": { "additionalProperties": true, "properties": { "y": { "title": "Y", "type": "string" }, "x": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "X" }, "kind": { "default": "scatter", "enum": [ "scatter", "line", "errorbar" ], "title": "Kind", "type": "string" }, "index": { "anyOf": [ { "$ref": "#/$defs/SeriesIndex" }, { "type": "null" } ], "default": { "from_zero": true, "to_units": null } } }, "required": [ "y" ], "title": "Series", "type": "object" }, "SeriesIndex": { "additionalProperties": false, "properties": { "from_zero": { "default": true, "title": "From Zero", "type": "boolean" }, "to_units": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "To Units" } }, "title": "SeriesIndex", "type": "object" } }, "additionalProperties": false, "required": [ "table", "ax_args" ] }
- Config:
extra: str = forbid
-
field table:
str
[Required] The name of the table loaded in memory to be plotted.
-
field nrows:
int
= 1 Number of rows in the figure grid.
-
field ncols:
int
= 1 Number of columns in the figure grid.
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
-
field fig_args:
Optional
[Dict
[str
,Any
]] = None Any optional method calls for the figure; passed to
matplotlib
.
-
field ax_args:
Sequence
[AxArgs
] [Required] Specifications of the figure axes, including selection of data for the plots.
-
field style:
Optional
[Dict
[str
,Any
]] = None Specification of overall
matplotlib
style.
- dgpost.utils.plot.apply_plot_style(style)
Updates the plot style with the given dictionary. For available kwargs see
matplotlib.rcParams
. If style is None, applies/resets to the default matplotlib style.- Parameters:
style (
dict
) – A dictionary object containing valid key/value pairs.- Return type:
None
- dgpost.utils.plot.plt_axes(ax, table, ax_args)
Processes ax_args and plots the data
- Parameters:
ax (
Axes
) – axes object to be plotted totable (
DataFrame
) – dataframe containing the dataax_args (
dict
) – arguments for the axes
- Returns:
ret – True if axes contain only timeseries as x-axis, False otherwise.
- Return type:
bool
- dgpost.utils.plot.plot(table, ax_args, save, style=None, fig_args=None, **grid_args)