Chart¶
-
class
qf_lib.plotting.charts.chart.
Chart
(start_x: Any = None, end_x: Any = None, upper_y: Any = None, lower_y: Any = None)[source]¶ Bases:
object
Abstract class for all the charts.
- Parameters
start_x (Any) – The upper bound of the x-axis.
end_x (Any) – The lower bound of the x-axis.
upper_y (Anny) – The upper bound of the y-axis.
lower_y (Anny) – The lower bound of the y-axis.
Methods
add_decorator
(decorator)Adds the new decorator to the chart.
Plots all DataElementDecorators added to a chart.
close
()Closes the window containing the figure.
determine_end_x
(start, series_list, …)Implements a heuristic for determining the x-axis end date based on a start date and series list.
Extract data from data element decorators added to the chart.
Returns the list of colors used for plotting on each Axes object.
plot
(figsize, float] = None)Plots the chart.
render_as_base64_image
(figsize, …)Plots the chart and returns the base64 image.
Creates a secondary axes if one has not already been created.
show
()Shows the chart.
Attributes
Axes is the object on which the chart is plotted (“the drawing area”).
A secondary axes on which data is plotted.
x and y ticks’ labels’ font weight. Acceptable values:
x and y ticks’ labels’ font size. Acceptable values:
Foreground color of all x and y ticks’ labels.
-
add_decorator
(decorator: qf_lib.plotting.decorators.chart_decorator.ChartDecorator) → None[source]¶ Adds the new decorator to the chart.
Each decorator must have a unique key that also doesn’t clash with any series keys because both are used for legend label data. If there is already a decorator registered under the specified key, the operation will raise the AssertionError.
- Parameters
decorator (ChartDecorator) – decorator to be added
-
apply_data_element_decorators
(data_element_decorators: List[DataElementDecorator])[source]¶ Plots all DataElementDecorators added to a chart. This function should set legend_artist field in each plotted DataElementDecorator (if applicable).
- Parameters
data_element_decorators (List[DataElementDecorator]) – non-empty list of DataElementDecorators that should be plotted on the chart
-
property
axes
¶ Axes is the object on which the chart is plotted (“the drawing area”).
-
classmethod
determine_end_x
(start: datetime.datetime, series_list: List[Union[qf_lib.containers.series.qf_series.QFSeries, qf_lib.plotting.decorators.data_element_decorator.DataElementDecorator]]) → datetime.datetime[source]¶ Implements a heuristic for determining the x-axis end date based on a start date and series list.
This is done by checking the year difference between the most recent date among the data points in all of the specified series and the specified start date. If the difference is greater than or equal to 10 years, the nearest date aligned to a 5 year boundary will be returned. Otherwise a datetime representing the nearest future January is returned.
-
classmethod
get_axes_colors
() → List[str][source]¶ Returns the list of colors used for plotting on each Axes object. Colors are taken from the currently set plotting style.
-
plot
(figsize: Tuple[float, float] = None)[source]¶ Plots the chart. The underlying figure stays hidden until the show() method is called.
- Parameters
figsize (Tuple[float, float]) – The figure size to draw the chart at in inches. This is a tuple of (width, height) passed directly to matplotlib’s
plot
function. The values are expressed in inches.
-
render_as_base64_image
(figsize: Tuple[float, float] = None, dpi: int = 250, optimise: bool = False) → str[source]¶ Plots the chart and returns the base64 image.
-
property
secondary_axes
¶ A secondary axes on which data is plotted. Created by calling setup_secondary_axes_if_necessary.
-
setup_secondary_axes_if_necessary
()[source]¶ Creates a secondary axes if one has not already been created.
-
tick_color
¶ Foreground color of all x and y ticks’ labels. Acceptable values: Any matplotlib color, for example “black” or “#8ac72e”.
-
tick_fontsize
¶ x and y ticks’ labels’ font size. Acceptable values: [size in points | ‘xx-small’ | ‘x-small’ | ‘small’ | ‘medium’ | ‘large’ | ‘x-large’ | ‘xx-large’ ]
-
tick_fontweight
¶ x and y ticks’ labels’ font weight. Acceptable values: For more info, see: http://matplotlib.org/api/text_api.html#matplotlib.text.Text Acceptable values: [a numeric value in range 0-1000 | ‘ultralight’ | ‘light’ | ‘normal’ | ‘regular’ | ‘book’ | ‘medium’ | ‘roman’ |‘semibold’ | ‘demibold’ | ‘demi’ | ‘bold’ | ‘heavy’ | ‘extra bold’ | ‘black’ ]