plots_builder module¶
Mixin for building plots out of subplots.
MetaPlotsBuilderMixin class¶
MetaPlotsBuilderMixin(
*args,
**kwargs
)
Meta class that exposes a read-only class property PlotsBuilderMixin.subplots.
Superclasses
builtins.type
Subclasses
subplots property¶
Subplots supported by PlotsBuilderMixin.plots().
PlotsBuilderMixin class¶
PlotsBuilderMixin()
Mixin that implements PlotsBuilderMixin.plots().
Required to be a subclass of Wrapping.
Subclasses
build_subplots_doc class method¶
PlotsBuilderMixin.build_subplots_doc(
source_cls=None
)
Build subplots documentation.
override_subplots_doc class method¶
PlotsBuilderMixin.override_subplots_doc(
__pdoc__,
source_cls=None
)
Call this method on each subclass that overrides subplots.
plots method¶
PlotsBuilderMixin.plots(
subplots=None,
tags=None,
column=None,
group_by=None,
silence_warnings=None,
template_mapping=None,
settings=None,
filters=None,
subplot_settings=None,
show_titles=None,
hide_id_labels=None,
group_id_labels=None,
make_subplots_kwargs=None,
**layout_kwargs
)
Plot various parts of this object.
Args
subplots:str,tuple,iterable,or dict-
Subplots to plot.
Each element can be either:
- a subplot name (see keys in PlotsBuilderMixin.subplots)
- a tuple of a subplot name and a settings dict as in PlotsBuilderMixin.subplots.
The settings dict can contain the following keys:
title: Title of the subplot. Defaults to the name.plot_func(required): Plotting function for custom subplots. Should write the supplied figurefigin-place and can return anything (it won't be used).xaxis_kwargs: Layout keyword arguments for the x-axis. Defaults todict(title='Index').yaxis_kwargs: Layout keyword arguments for the y-axis. Defaults to empty dict.tags,check_{filter},inv_check_{filter},resolve_plot_func,pass_{arg},resolve_path_{arg},resolve_{arg}andtemplate_mapping: The same as in StatsBuilderMixin forcalc_func.- Any other keyword argument that overrides the settings or is passed directly to
plot_func.
If
resolve_plot_funcis True, the plotting function may "request" any of the following arguments by accepting them or ifpass_{arg}was found in the settings dict:- Each of AttrResolver.self_aliases: original object (ungrouped, with no column selected)
group_by: won't be passed if it was used in resolving the first attribute ofplot_funcspecified as a path, usepass_group_by=Trueto pass anywaycolumnsubplot_nametrace_names: list with the subplot name, can't be used in templatesadd_trace_kwargs: dict with subplot row and column indexxrefyrefxaxisyaxisx_domainy_domainfigsilence_warnings- Any argument from
settings - Any attribute of this object if it meant to be resolved (see AttrResolver.resolve_attr())
Note
Layout-related resolution arguments such as
add_trace_kwargsare unavailable before filtering and thus cannot be used in any templates but can still be overridden.Pass
subplots='all'to plot all supported subplots. tags:stroriterable- See
tagsin StatsBuilderMixin. column:str- See
columnin StatsBuilderMixin. group_by:any- See
group_byin StatsBuilderMixin. silence_warnings:bool- See
silence_warningsin StatsBuilderMixin. template_mapping:mapping-
See
template_mappingin StatsBuilderMixin.Applied on
settings,make_subplots_kwargs, andlayout_kwargs, and then on each subplot settings. filters:dict- See
filtersin StatsBuilderMixin. settings:dict- See
settingsin StatsBuilderMixin. subplot_settings:dict- See
metric_settingsin StatsBuilderMixin. show_titles:bool- Whether to show the title of each subplot.
hide_id_labels:bool-
Whether to hide identical legend labels.
Two labels are identical if their name, marker style and line style match.
group_id_labels:bool- Whether to group identical legend labels.
make_subplots_kwargs:dict- Keyword arguments passed to
plotly.subplots.make_subplots. **layout_kwargs- Keyword arguments used to update the layout of the figure.
Note
PlotsBuilderMixin and StatsBuilderMixin are very similar. Some artifacts follow the same concept, just named differently:
plots_defaultsvsstats_defaultssubplotsvsmetricssubplot_settingsvsmetric_settings
See further notes under StatsBuilderMixin.
Usage
See vectorbt.portfolio.base for examples.
plots_defaults property¶
Defaults for PlotsBuilderMixin.plots().
See plots_builder in settings.
subplots class variable¶
Subplots supported by PlotsBuilderMixin.
Config({})
Returns PlotsBuilderMixin._subplots, which gets (deep) copied upon creation of each instance. Thus, changing this config won't affect the class.
To change subplots, you can either change the config in-place, override this property, or overwrite the instance variable PlotsBuilderMixin._subplots.
writeable_attrs property¶
Set of writeable attributes that will be saved/copied along with the config.