styling
styling ¶
Grid
pydantic-model
¶
Bases: HashableBase
Container for major and minor grid line configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
major |
GridAxis
|
Configuration for major grid lines. |
minor |
GridAxis
|
Configuration for minor grid lines. |
enable_minor_ticks |
bool
|
Whether to enable minor ticks on the axes. |
Show JSON schema:
{
"$defs": {
"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"
},
"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"
}
},
"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"
}
Config:
extra:'forbid'
Fields:
from_theme
classmethod
¶
from_theme(name: GridTheme) -> Grid
Predefined themes for common grid styles.
Source code in src/trendify/api/styling/grid.py
union_from_iterable
classmethod
¶
Gets the most inclusive grid format from a list of Grid objects. Requires that all GridAxis fields (major/minor) are consistent across the objects.
Source code in src/trendify/api/styling/grid.py
GridAxis
pydantic-model
¶
Bases: HashableBase
Controls styling and visibility for one type of grid (major or minor).
Attributes:
| Name | Type | Description |
|---|---|---|
show |
bool
|
Whether to display this grid axis. |
pen |
Pen
|
Style and label information for drawing to matplotlib axes. |
Show JSON schema:
{
"$defs": {
"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"
}
},
"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"
}
Config:
extra:'forbid'
Fields:
Legend
pydantic-model
¶
Bases: HashableBase
Configuration container for Matplotlib legend styling and placement.
The Legend class controls the appearance and position of the plot legend.
Placement is governed by a combination of the loc and bbox_to_anchor
parameters, mirroring Matplotlib's Axes.legend().
Attributes:
| Name | Type | Description |
|---|---|---|
visible |
bool
|
Whether the legend should be displayed. Defaults to True. |
title |
str | None
|
Title displayed above the legend entries. |
framealpha |
float
|
Opacity of the legend background. 1 = fully opaque, 0 = fully transparent. |
loc |
LegendLocation
|
Anchor point for the legend (e.g., upper right, lower left). See |
ncol |
int
|
Number of columns to arrange legend entries into. |
fancybox |
bool
|
Whether to draw a rounded (True) or square (False) legend frame. |
edgecolor |
str
|
Color of the legend frame border. Default is "black". |
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 Good starter values for common placements:
|
Show JSON schema:
{
"$defs": {
"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"
}
},
"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"
}
Fields:
Marker
pydantic-model
¶
Bases: HashableBase
Defines marker for scattering to matplotlib
Attributes:
| Name | Type | Description |
|---|---|---|
color |
str
|
Color of line |
size |
float
|
Line width |
alpha |
float
|
Opacity from 0 to 1 (inclusive) |
zorder |
float
|
Prioritization |
label |
Union[str, None]
|
Legend label |
symbol |
str
|
Matplotlib symbol string |
Show JSON schema:
{
"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"
}
Config:
extra:'forbid'
Fields:
-
color(str) -
size(float) -
alpha(float) -
zorder(float) -
label(str | None) -
symbol(str) -
plotly_symbol(str) -
rgba(str)
rgba
pydantic-field
¶
rgba: str
Convert the pen's color to rgba string format.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Color in 'rgba(r,g,b,a)' format where r,g,b are 0-255 and a is 0-1 |
as_scatter_plot_kwargs ¶
Returns:
| Type | Description |
|---|---|
dict
|
dictionary of |
Source code in src/trendify/api/styling/marker.py
from_pen
classmethod
¶
Converts Pen to marker with the option to specify a symbol
get_contrast_color ¶
Returns 'white' or 'black' to provide the best contrast against the pen's color, taking into account the alpha (transparency) value of the line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
background_luminance
|
float
|
The luminance of the background (default is 1.0 for white). |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
'white' or 'black' |