trace
trace ¶
Trace2D
pydantic-model
¶
Bases: XYData
A collection of points comprising a trace. Use the Trace2D.from_xy constructor.
Attributes:
| Name | Type | Description |
|---|---|---|
points |
List[Point2D]
|
List of points. Usually the points would have null values
for |
pen |
Pen
|
Style and label information for drawing to matplotlib axes. Only the label information is used in Grafana. Eventually style information will be used in grafana. |
tags |
Tags
|
Tags to be used for sorting data. |
metadata |
dict[str, str]
|
A dictionary of metadata to be used as a tool tip for mousover in grafana |
Show JSON schema:
{
"$defs": {
"AxisScale": {
"enum": [
"linear",
"log"
],
"title": "AxisScale",
"type": "string"
},
"Format2D": {
"additionalProperties": false,
"description": "Formatting data for matplotlib figure and axes\n\nAttributes:\n title_fig (Optional[str]): Sets [figure title][matplotlib.figure.Figure.suptitle]\n legend (Optional[Legend]): Sets [legend style][trendify.api.styling.legend.Legend]\n title_ax (Optional[str]): Sets [axis title][matplotlib.axes.Axes.set_title]\n label_x (Optional[str]): Sets [x-axis label][matplotlib.axes.Axes.set_xlabel]\n label_y (Optional[str]): Sets [y-axis label][matplotlib.axes.Axes.set_ylabel]\n lim_x_min (float | None): Sets [x-axis lower bound][matplotlib.axes.Axes.set_xlim]\n lim_x_max (float | None): Sets [x-axis upper bound][matplotlib.axes.Axes.set_xlim]\n lim_y_min (float | None): Sets [y-axis lower bound][matplotlib.axes.Axes.set_ylim]\n lim_y_max (float | None): Sets [y-axis upper bound][matplotlib.axes.Axes.set_ylim]\n grid (Grid | None): Sets the [grid][matplotlib.pyplot.grid]\n scale_x (AxisScale): Sets the x axis scale to an option from [AxisScale][trendify.api.formats.format2d.AxisScale]\n scale_y (AxisScale): Sets the y axis scale to an option from [AxisScale][trendify.api.formats.format2d.AxisScale]",
"properties": {
"title_fig": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Title Fig"
},
"legend": {
"anyOf": [
{
"$ref": "#/$defs/Legend"
},
{
"type": "null"
}
],
"default": {
"visible": true,
"title": null,
"framealpha": 1.0,
"loc": "best",
"ncol": 1,
"fancybox": true,
"edgecolor": "black",
"zorder": 10,
"bbox_to_anchor": null
}
},
"title_ax": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Title Ax"
},
"label_x": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Label X"
},
"label_y": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Label Y"
},
"lim_x_min": {
"anyOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"default": null,
"title": "Lim X Min"
},
"lim_x_max": {
"anyOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"default": null,
"title": "Lim X Max"
},
"lim_y_min": {
"anyOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"default": null,
"title": "Lim Y Min"
},
"lim_y_max": {
"anyOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"default": null,
"title": "Lim Y Max"
},
"grid": {
"anyOf": [
{
"$ref": "#/$defs/Grid"
},
{
"type": "null"
}
],
"default": null
},
"scale_x": {
"$ref": "#/$defs/AxisScale",
"default": "linear"
},
"scale_y": {
"$ref": "#/$defs/AxisScale",
"default": "linear"
}
},
"title": "Format2D",
"type": "object"
},
"Grid": {
"additionalProperties": false,
"description": "Container for major and minor grid line configuration.\n\nAttributes:\n major (GridAxis): Configuration for major grid lines.\n minor (GridAxis): Configuration for minor grid lines.\n enable_minor_ticks (bool): Whether to enable minor ticks on the axes.",
"properties": {
"major": {
"$ref": "#/$defs/GridAxis",
"default": {
"show": false,
"pen": {
"alpha": 1.0,
"color": "gray",
"label": null,
"linestyle": "-",
"size": 0.75,
"zorder": 0.0
}
}
},
"minor": {
"$ref": "#/$defs/GridAxis",
"default": {
"show": false,
"pen": {
"alpha": 1.0,
"color": "gray",
"label": null,
"linestyle": "-",
"size": 0.75,
"zorder": 0.0
}
}
},
"enable_minor_ticks": {
"default": false,
"title": "Enable Minor Ticks",
"type": "boolean"
},
"zorder": {
"default": -1,
"title": "Zorder",
"type": "number"
}
},
"title": "Grid",
"type": "object"
},
"GridAxis": {
"additionalProperties": false,
"description": "Controls styling and visibility for one type of grid (major or minor).\n\nAttributes:\n show (bool): Whether to display this grid axis.\n pen (Pen): Style and label information for drawing to matplotlib axes.",
"properties": {
"show": {
"default": false,
"title": "Show",
"type": "boolean"
},
"pen": {
"$ref": "#/$defs/Pen",
"default": {
"color": "gray",
"size": 0.75,
"alpha": 1.0,
"zorder": 0.0,
"linestyle": "-",
"label": null
}
}
},
"title": "GridAxis",
"type": "object"
},
"Legend": {
"description": "Configuration container for Matplotlib legend styling and placement.\n\nThe `Legend` class controls the appearance and position of the plot legend.\nPlacement is governed by a combination of the `loc` and `bbox_to_anchor`\nparameters, mirroring Matplotlib's `Axes.legend()`.\n\nAttributes:\n visible (bool): Whether the legend should be displayed. Defaults to True.\n title (str | None): Title displayed above the legend entries.\n framealpha (float): Opacity of the legend background. 1 = fully opaque, 0 = fully transparent.\n loc (LegendLocation): Anchor point for the legend (e.g., upper right, lower left). See `LegendLocation` enum for options.\n ncol (int): Number of columns to arrange legend entries into.\n fancybox (bool): Whether to draw a rounded (True) or square (False) legend frame.\n edgecolor (str): Color of the legend frame border. Default is \"black\".\n bbox_to_anchor (tuple[float, float] | None): Offset position of the legend in figure or axes coordinates. If None, the legend is placed inside the axes using `loc`.\n\n Good starter values for common placements:\n\n - **Inside (default)**:\n ```python\n bbox_to_anchor=None\n ```\n - **Outside right**:\n ```python\n loc=LegendLocation.CENTER_LEFT\n bbox_to_anchor=(1.02, 0.5)\n ```\n - **Outside left**:\n ```python\n loc=LegendLocation.CENTER_RIGHT\n bbox_to_anchor=(-0.02, 0.5)\n ```\n - **Outside top**:\n ```python\n loc=LegendLocation.LOWER_CENTER\n bbox_to_anchor=(0.5, 1.02)\n ```\n - **Outside bottom**:\n ```python\n loc=LegendLocation.UPPER_CENTER\n bbox_to_anchor=(0.5, -0.02)\n ```",
"properties": {
"visible": {
"default": true,
"title": "Visible",
"type": "boolean"
},
"title": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Title"
},
"framealpha": {
"default": 1,
"title": "Framealpha",
"type": "number"
},
"loc": {
"$ref": "#/$defs/LegendLocation",
"default": "best"
},
"ncol": {
"default": 1,
"title": "Ncol",
"type": "integer"
},
"fancybox": {
"default": true,
"title": "Fancybox",
"type": "boolean"
},
"edgecolor": {
"default": "black",
"title": "Edgecolor",
"type": "string"
},
"zorder": {
"default": 10,
"title": "Zorder",
"type": "integer"
},
"bbox_to_anchor": {
"anyOf": [
{
"maxItems": 2,
"minItems": 2,
"prefixItems": [
{
"type": "number"
},
{
"type": "number"
}
],
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Bbox To Anchor"
}
},
"title": "Legend",
"type": "object"
},
"LegendLocation": {
"enum": [
"best",
"upper right",
"upper left",
"lower left",
"lower right",
"right",
"center left",
"center right",
"lower center",
"upper center",
"center"
],
"title": "LegendLocation",
"type": "string"
},
"Marker": {
"additionalProperties": false,
"description": "Defines marker for scattering to matplotlib\n\nAttributes:\n color (str): Color of line\n size (float): Line width\n alpha (float): Opacity from 0 to 1 (inclusive)\n zorder (float): Prioritization\n label (Union[str, None]): Legend label\n symbol (str): Matplotlib symbol string",
"properties": {
"color": {
"default": "k",
"title": "Color",
"type": "string"
},
"size": {
"default": 5,
"title": "Size",
"type": "number"
},
"alpha": {
"default": 1,
"title": "Alpha",
"type": "number"
},
"zorder": {
"default": 0,
"title": "Zorder",
"type": "number"
},
"label": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Label"
},
"symbol": {
"default": ".",
"title": "Symbol",
"type": "string"
}
},
"title": "Marker",
"type": "object"
},
"Pen": {
"additionalProperties": false,
"description": "Defines the pen drawing to matplotlib.\n\nAttributes:\n color (str): Color of line\n size (float): Line width\n alpha (float): Opacity from 0 to 1 (inclusive)\n linestyle (Union[str, Tuple[int, Tuple[int, ...]]]): Linestyle to plot. Supports `str` or `tuple` definition ([matplotlib documentation](https://matplotlib.org/stable/gallery/lines_bars_and_markers/linestyles.html)).\n zorder (float): Prioritization\n label (Union[str, None]): Legend label",
"properties": {
"color": {
"anyOf": [
{
"maxItems": 3,
"minItems": 3,
"prefixItems": [
{
"type": "number"
},
{
"type": "number"
},
{
"type": "number"
}
],
"type": "array"
},
{
"maxItems": 4,
"minItems": 4,
"prefixItems": [
{
"type": "number"
},
{
"type": "number"
},
{
"type": "number"
},
{
"type": "number"
}
],
"type": "array"
},
{
"type": "string"
}
],
"default": "k",
"title": "Color"
},
"size": {
"default": 1,
"title": "Size",
"type": "number"
},
"alpha": {
"default": 1,
"title": "Alpha",
"type": "number"
},
"zorder": {
"default": 0,
"title": "Zorder",
"type": "number"
},
"linestyle": {
"anyOf": [
{
"type": "string"
},
{
"maxItems": 2,
"minItems": 2,
"prefixItems": [
{
"type": "integer"
},
{
"items": {
"type": "integer"
},
"type": "array"
}
],
"type": "array"
}
],
"default": "-",
"title": "Linestyle"
},
"label": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Label"
}
},
"title": "Pen",
"type": "object"
},
"Point2D": {
"additionalProperties": false,
"description": "Defines a point to be scattered onto xy plot.\n\nAttributes:\n tags (Tags): Tags to be used for sorting data.\n x (float | str): X value for the point.\n y (float | str): Y value for the point.\n marker (Marker | None): Style and label information for scattering points to matplotlib axes.\n Only the label information is used in Grafana.\n Eventually style information will be used in grafana.\n metadata (dict[str, str]): A dictionary of metadata to be used as a tool tip for mousover in grafana",
"properties": {
"tags": {
"items": {
"anyOf": []
},
"title": "Tags",
"type": "array"
},
"metadata": {
"additionalProperties": {
"type": "string"
},
"default": {},
"title": "Metadata",
"type": "object"
},
"format2d": {
"anyOf": [
{
"$ref": "#/$defs/Format2D"
},
{
"type": "null"
}
],
"default": null
},
"x": {
"anyOf": [
{
"type": "number"
},
{
"type": "string"
}
],
"title": "X"
},
"y": {
"anyOf": [
{
"type": "number"
},
{
"type": "string"
}
],
"title": "Y"
},
"marker": {
"anyOf": [
{
"$ref": "#/$defs/Marker"
},
{
"type": "null"
}
],
"default": {
"color": "k",
"size": 5.0,
"alpha": 1.0,
"zorder": 0.0,
"label": null,
"symbol": "."
}
}
},
"required": [
"tags",
"x",
"y"
],
"title": "Point2D",
"type": "object"
}
},
"additionalProperties": false,
"description": "A collection of points comprising a trace.\nUse the [Trace2D.from_xy][trendify.api.Trace2D.from_xy] constructor.\n\nAttributes:\n points (List[Point2D]): List of points. Usually the points would have null values\n for `marker` and `format2d` fields to save space.\n pen (Pen): Style and label information for drawing to matplotlib axes.\n Only the label information is used in Grafana.\n Eventually style information will be used in grafana.\n tags (Tags): Tags to be used for sorting data.\n metadata (dict[str, str]): A dictionary of metadata to be used as a tool tip for mousover in grafana",
"properties": {
"tags": {
"items": {
"anyOf": []
},
"title": "Tags",
"type": "array"
},
"metadata": {
"additionalProperties": {
"type": "string"
},
"default": {},
"title": "Metadata",
"type": "object"
},
"format2d": {
"anyOf": [
{
"$ref": "#/$defs/Format2D"
},
{
"type": "null"
}
],
"default": null
},
"points": {
"items": {
"$ref": "#/$defs/Point2D"
},
"title": "Points",
"type": "array"
},
"pen": {
"$ref": "#/$defs/Pen",
"default": {
"color": "k",
"size": 1.0,
"alpha": 1.0,
"zorder": 0.0,
"linestyle": "-",
"label": null
}
}
},
"required": [
"tags",
"points"
],
"title": "Trace2D",
"type": "object"
}
Config:
extra:'forbid'
Fields:
x
pydantic-field
¶
y
pydantic-field
¶
from_xy
classmethod
¶
from_xy(
tags: Tags,
x: NDArray[Shape["*"], float],
y: NDArray[Shape["*"], float],
pen: Pen = Pen(),
format2d: Format2D | None = None,
)
Creates a list of Point2Ds from xy data and returns a new Trace2D product.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tags
|
Tags
|
Tags used to sort data products |
required |
x
|
NDArray[Shape['*'], float]
|
x values |
required |
y
|
NDArray[Shape['*'], float]
|
y values |
required |
pen
|
Pen
|
Style and label for trace |
Pen()
|
format2d
|
Format2D | None
|
Format to apply to plot |
None
|
Source code in src/trendify/api/plotting/trace.py
plot_to_ax ¶
plot_to_ax(ax: Axes)
Plots xy data from trace to a matplotlib axes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
axes to which xy data should be plotted |
required |
propagate_format2d_and_pen ¶
propagate_format2d_and_pen(marker_symbol: str = '.') -> None
Propagates format and style info to all self.points (in-place).
I thought this would be useful for grafana before I learned better methods for propagating the data.
It still may end up being useful if my plotting method changes. Keeping for potential future use case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
marker_symbol
|
str
|
Valid matplotlib marker symbol |
'.'
|