Auto Generated Documentation¶
Version 0.8.0
- rick.add_bar_annotations(ax: axes, df: DataFrame, upper: float, precision: int, percent: bool, horizontal: bool, additional_annotations: dict) None [source]¶
Adds bar annotations to bar charts, and other annotations if specified.
- Parameters:
ax (plt.axes) – Matplotlib axes object corresponding to plot.
df (pd.DataFrame) – Dataset being plotted.
upper (float) – Bar value used for determining placement of annotation.
precision (int) – Decimal points in the annotations.
percent (bool) – Flag determining whether to show percentage change between baseline column (assumed to be the first column) and remaining columns.
horizontal (bool) – Flag to indicate if this is a horizontal bar graph.
additional_annotations (dict) – Dictionary with keys of type (int, int) and values of type (str), indicating the coordinates and annotation to be added.
- rick.add_shaded_areas(ax: axes, df: DataFrame, shaded_areas: dict) None [source]¶
Adds shaded areas to plot if specified by user.
Paramaters¶
- dfpd.DataFrame
Data for the grouped bar chart.
- axplt.axes
Axis object being used.
- shaded_areasdict
Dictionary with the following format: {(label, colour): (x_start, x_end)}. Start and end x coordinates indicate range of shaded region and must be specified. Label can be specified or left as None. Colour can be specified or left as None in which case light grey is used by default.
- rick.calculate_delta(max_value: float, min_value: float) -> (<class 'float'>, <class 'float'>)[source]¶
Returns parameters used to find the size of the y or x axis increments.
- Parameters:
max_value (float) – Maximum value of data being plotted in non-index axis.
min_value (float) – Minimum value of data being plotted in non-index axis.
- Returns:
float – The spacing between ticks in non-index axis.
float – Order of magnitude of spacing.
- rick.calculate_params(df: ~pandas.core.frame.DataFrame, param_axis: str, **kwargs: dict) -> (<class 'float'>, <class 'float'>, <class 'float'>, <class 'float'>)[source]¶
Checks if minimum, maximum and increment values are passed into the plotting function for the specified axis, and returns these. Otherwise, calculates them.
- Parameters:
df (pd.DataFrame) – Data for the line chart.
param_axis (str) – Axis along which max, min, upper, inc values should be calculated.
xmin (float, optional) – Minimum value of x axis.
xmax (float, optional) – Maximum value of x axis.
xinc (float, optional) – The increment of ticks on the x axis.
ymin (float, optional) – Minimum value of y axis
ymax (float, optional) – Maximum value of y axis.
yinc (float, optional) – The increment of ticks on the y axis.
- Returns:
max_value (float) – Maximum value along param_axis
min_value (float) – Minimum value along param_axis
inc (float) – Increment of ticks along param_axis
upper (float) – Value used for placing of annotations.
- class rick.charts[source]¶
Class defining all the charting functions.
- bar_chart(xlab, **kwargs)[source]¶
Creates a bar chart
- Parameters:
data (dataframe) – Data for the bar chart. The dataframe must have 2 columns, the first representing the y ticks, and the second representing the data
xlab (str) – Label for the x axis.
xmax (int, optional, default is the max s value) – The max value of the y axis
xmin (int, optional, default is 0) – The minimum value of the x axis
precision (int, optional, default is -1) – Decimal places in the annotations
xinc (int, optional) – The increment of ticks on the x axis.
- Returns:
fig – Matplotlib fig object
ax – Matplotlib ax object
- chloro_map(df, lower, upper, title, **kwargs)[source]¶
Creates a chloropleth map
- Parameters:
con (SQL connection object) – Connection object needed to connect to the RDS
df (GeoPandas Dataframe) – Data for the chloropleth map. The data must only contain 2 columns; the first column has to be the geom column and the second has to be the data that needs to be mapped.
lower (int) – Lower bound for colourmap
upper (int) – Upper bound for the colourmap
title (str) – Legend label
subway (boolean, optional, default: False) – True to display subway on the map
island (boolean, optional, defailt: True) – False to grey out the Toronto island
cmap (str, optional, default: YlOrRd) – Matplotlib colourmap to use for the map
unit (str, optional) – Unit to append to the end of the legend tick
nbins (int, optional, defualt: 2) – Number of ticks in the colourmap
- Returns:
fig – Matplotlib fig object
ax – Matplotlib ax object
- horizontal_grouped_bar_chart(**kwargs: dict) -> (<function figure at 0xffff8521d240>, <function axes at 0xffff8521da20>)[source]¶
Creates a horizontal grouped bar chart. Number of bars in each group to plot is determined from the number of columns in input dataframe, while the number of groups is determined by the number of rows.
- Parameters:
Required –
data (pd.DataFrame) – Data for the grouped bar chart.
Optional –
ylab (str) – Label for the y axis.
xlab (str) – Label for the x axis.
xmax (float) – The max value of the x axis.
xmin (float) – The minimum value of the x axis Should include this if minimum < 0.
xinc (float) – The increment of ticks on the x axis.
ax (plt.axes) – The axis that the plot will be located on.
plot_size ((int, int)) – Custom plot dimensions.
precision (int) – Decimal points in the annotations.
percent (bool) – Flag determining whether to show percentage change between baseline column (assumed to be the first column) and remaining columns.
additional_annotations (dict) – Dictionary with keys of type (int, int) and values of type (str), indicating the coordinates and annotation to be added.
legend (list[str]) – A list of labels to be used for the legend.
- Returns:
fig – Matplotlib fig object
ax – Matplotlib ax object
- line_chart(ylab, xlab, **kwargs)[source]¶
Creates a line chart. x axis must be modified manually
- Parameters:
data (array like or scalar) – Data for the line chart.
ylab (str) – Label for the y axis.
xlab (str) – Label for the x axis.
ymax (int, optional, default is the max y value) – The max value of the y axis
ymin (int, optional, default is 0) – The minimum value of the y axis
baseline (array like or scalar, optional, default is None) – Data for another line representing the baseline.
yinc (int, optional) – The increment of ticks on the y axis.
- Returns:
fig – Matplotlib fig object
ax – Matplotlib ax object
props – Dictionary of the text annotation properties
- multi_linechart(ylab: str, xlab: str, **kwargs: dict) -> (<function figure at 0xffff8521d240>, <function axes at 0xffff8521da20>)[source]¶
Creates a line chart of one or more lines. Number of lines to plot determined from columns in input dataframe.
- Parameters:
data (pd.DataFrame) – Data for the line chart.
ylab (str) – Label for the y axis.
xlab (str) – Label for the x axis.
ymax (float, optional) – The max value of the y axis.
ymin (float, optional) – The min value of the y axis. Should include this if ymin < 0.
yinc (float, optional) – The increment of ticks on the y axis.
ax (plt.axes, optional) – The axis that the plot will be located on.
plot_size ((int, int), optional) – The dimensions of the plot if given a custom size.
minor_x (bool, optional) – When set to True, a minor grid is added to the plot along x axis.
minor_y (bool, optional) – When set to True, a minor grid is added to the plot along y axis.
num_minor_x (int, optional) – The number of minor ticks between major ticks along the x axis.
num_minor_y (int, optional) – The number of minor ticks between major ticks along the y axis.
shaded_areas (dict[(str, str): (Any, Any)], optional) – Start and end x coordinates indicate range of shaded region and must be specified. Label can be specified or left as None. Colour can be specified or left as None in which case light grey is used by default.
- Returns:
fig – Matplotlib fig object
ax – Matplotlib ax object
- stacked_chart(xlab, lab1, lab2, **kwargs)[source]¶
Creates a stacked bar chart comparing 2 sets of data
- Parameters:
data (dataframe) – Data for the stacked bar chart. The dataframe must have 3 columns, the first representing the y ticks, the second representing the baseline, and the third representing the next series of data.
xlab (str) – Label for the x axis.
lab1 (str) – Label in the legend for the baseline
lab2 (str) – Label in the legend fot the next data series
xmax (int, optional, default is the max s value) – The max value of the y axis
xmin (int, optional, default is 0) – The minimum value of the x axis
precision (int, optional, default is -1) – Decimal places in the annotations
percent (boolean, optional, default is False) – Whether the annotations should be formatted as percentages
xinc (int, optional) – The increment of ticks on the x axis.
- Returns:
fig – Matplotlib fig object
ax – Matplotlib ax object
- stacked_chart_quad(xlab, lab1, lab2, lab3, lab4, **kwargs)[source]¶
Creates a stacked bar chart comparing 4 sets of data
- Parameters:
data (dataframe) – Data for the stacked bar chart. The dataframe must have 5 columns, the first representing the y ticks, the second representing the baseline, and the third representing the next series of data.
xlab (str) – Label for the x axis.
lab1 (str) – Label in the legend for the baseline
lab2 (str) – Label in the legend fot the next data series
xmax (int, optional, default is the max s value) – The max value of the y axis
xmin (int, optional, default is 0) – The minimum value of the x axis
precision (int, optional, default is -1) – Decimal places in the annotations
percent (boolean, optional, default is False) – Whether the annotations should be formatted as percentages
xinc (int, optional) – The increment of ticks on the x axis.
- Returns:
fig – Matplotlib fig object
ax – Matplotlib ax object
- tow_chart(ylab, **kwargs)[source]¶
Creates a 7 day time of week line chart. Each data point represents 1 hour out of 168 hours.
- Parameters:
data (array like or scalar) – Data for the tow chart. Data must only have 168 entries, with row 0 representing Monday at midnight.
ylab (str) – Label for the y axis.
ymax (int, optional, default is the max y value) – The max value of the y axis
ymin (int, optional, default is 0) – The minimum value of the y axis
yinc (int, optional) – The increment of ticks on the y axis.
- Returns:
fig – Matplotlib fig object
ax – Matplotlib ax object
props – Dictionary of the text annotation properties
- vertical_grouped_bar_chart(**kwargs: dict) -> (<function figure at 0xffff8521d240>, <function axes at 0xffff8521da20>)[source]¶
Creates a vertical grouped bar chart. Number of bars in each group to plot is determined from the number of columns in input dataframe, while the number of groups is determined by the number of rows.
- Parameters:
Required –
data (pd.DataFrame) – Data for the grouped bar chart.
Optional –
ylab (str) – Label for the y axis.
xlab (str) – Label for the x axis.
ymax (float) – The max value of the y axis.
ymin (float) – The minimum value of the y axis Should include this if minimum < 0.
yinc (float) – The increment of ticks on the y axis.
ax (plt.axes) – The axis that the plot will be located on.
plot_size ((int, int)) – Custom plot dimensions.
precision (int) – Decimal points in the annotations.
percent (int) – Flag determining whether to show percentage change between baseline column (assumed to be the first column) and remaining columns.
additional_annotations (dict) – Dictionary with keys of type (int, int) and values of type (str), indicating the coordinates and annotation to be added.
legend (list[str]) – A list of string objects to be used for the legend.
- Returns:
fig – Matplotlib fig object
ax – Matplotlib ax object
- rick.func()¶
Function to set global settings for the charts class.
- rick.general_grouped_bar_chart(data: ~pandas.core.frame.DataFrame, param_axis: str, index_axis: str, standard_plot_size: (<class 'int'>, <class 'int'>), horizontal: bool, grid_x: bool = True, grid_y: bool = True, **kwargs: dict) -> (<function figure at 0xffff8521d240>, <function axes at 0xffff8521da20>)[source]¶
Creates a horizontal or vertical grouped bar chart. Number of bars in each group to plot is determined from the number of columns in input dataframe, while the number of groups is determined by the number of rows.
- Parameters:
data (pd.DataFrame) – Data for the grouped bar chart.
param_axis (str) – Axis along which bars are plotted.
index_axis (str) – Axis containing labels for bars.
standard_plot_size ((int, int)) – The standard size depending on the type of graph (horizontal or vertical).
horizontal (bool) – Flag indicating whether plot is horizontal.
ylab (str, optional) – Label for the y axis.
xlab (str, optional) – Label for the x axis.
ymax (xmax or) – The max value of the x or y axis.
ymin (xmin or) – The minimum value of the x or y axis Should include this if minimum < 0.
yinc (xinc or) – The increment of ticks on the x or y axis.
ax (plt.axes, optional) – The axis that the plot will be located on.
plot_size ((int, int), optional) – Custom plot dimensions.
precision (int, optional) – Decimal points in the annotations.
percent (bool, optional) – Flag determining whether to show percentage change between baseline column (assumed to be the first column) and remaining columns.
additional_annotations (dict, optional) – Dictionary with keys of type (int, int) and values of type (str), indicating the coordinates and annotation to be added.
legend (list[str], optional) – A list of labels to be used for the legend.
- Returns:
fig – Matplotlib fig object
ax – Matplotlib ax object
- class rick.geo[source]¶
Class for additional gis layers needed for the cloropleth map.
- island()[source]¶
Function to return a layer of the Toronto island. Since the island is classified in the same neighbourhood as the waterfront, in some cases its not completely accurate to show the island shares the same data as the waterfront.
- Parameters:
con (SQL connection object) – Connection object needed to connect to the RDS
- Returns:
Geopandas Dataframe of the Toronto island.
- Return type:
gdf
- rick.horizontal_bar_annotations(df: DataFrame, ax: axes, bar_width: float, upper: float, precision: int, percent: bool) None [source]¶
Adds value annotations to horizontal grouped or regular bar charts.
- Parameters:
df (pd.DataFrame) – Input dataframe being plotted.
ax (plt.axes) – Axis object corresponding to the plot.
bar_width (float) – The width of each bar.
upper (float) – Bar value used for determining placement of annotation.
precision (int) – Decimal points in the annotations.
percent (bool) – Flag determining whether to show percentage change between baseline column (assumed to be the first column) and remaining columns.
- rick.init_fig(axis: ~matplotlib.pyplot.axes) -> (<function figure at 0xffff8521d240>, <function axes at 0xffff8521da20>)[source]¶
Sets the plot fig and axes objects to be the ones specified by the user or creates new ones.
- Parameters:
axis (plt.axes) – Axis object for the plot prespecified by the user.
- Returns:
fig – Matplotlib figure object.
ax – Matplotlib axis object.
- rick.plot_grouped_bar_data(df: ~pandas.core.frame.DataFrame, ax: ~matplotlib.pyplot.axes, legend: list[str], horizontal: bool) -> (<function figure at 0xffff8521d240>, <function axes at 0xffff8521da20>)[source]¶
Plots all columns in the input dataframe as bars in a grouped bar graph. Also adds a legend if a list of strings is provided.
- Parameters:
df (pd.DataFrame) – Input dataframe being plotted.
ax (plt.axes) – Axis object to be used for the plot if specified by user.
legend (list[str]) – List of labels to be used for the legend.
horizontal (bool) – Flag indicating whether this is a horizontal plot.
- Returns:
fig – Matplotlib figure object.
ax – Matplotlib axis object.
- rick.plot_line_data(df: ~pandas.core.frame.DataFrame, axis: ~matplotlib.pyplot.axes, legend: list[str]) -> (<function figure at 0xffff8521d240>, <function axes at 0xffff8521da20>)[source]¶
Plots all columns in the input dataframe as lines in one graph on the specified axis object.
- Parameters:
df (pd.DataFrame) – Data to be plotted.
axis (plt.axes) – Prespecified axis to be used for the plot.
legend (list[str]) – List of labels to be used for the legend.
- Returns:
fig – Matplotlib fig object
ax – Matplotlib ax object
- rick.set_grid(ax: axes, grid_x: bool, grid_y: bool, grid_minor_x: bool, grid_minor_y: bool) None [source]¶
Sets the grid for plot.
- Parameters:
ax (plt.axes) – Axis object corresponding to plot.
grid_x (bool) – Flag indicating whether to add a grid along the x axis.
grid_y (bool) – Flag indicating whether to add a grid along the y axis.
grid_minor_x (bool, optional) – When set to True, a minor grid is added to the plot along x axis.
grid_minor_y (bool, optional) – When set to True, a minor grid is added to the plot along y axis.
- rick.set_labels(ax: axes, xlab: str, ylab: str) None [source]¶
Set the labels of the y and x axes.
- Parameters:
ax (plt.axes) – Matplotlib axes object.
xlab (str) – Label of x axis.
ylab (str) – Label of y axis.
- rick.set_plot_style(fig: ~matplotlib.pyplot.figure, ax: ~matplotlib.pyplot.axes, plot_size: (<class 'int'>, <class 'int'>), grid_x: bool, grid_y: bool, min_value: float, max_value: float, param_axis: str, grid_minor_x: bool = False, grid_minor_y: bool = False) None [source]¶
Sets size, background and grid for plot.
- Parameters:
fig (plt.figure) – Figure object corresponding to plot.
ax (plt.axes) – Axis object corresponding to plot.
plot_size ((int, int)) – The dimensions of the plot in inches.
grid_x (bool) – Whether there is a grid parallel to x ticks.
grid_y (bool) – Whether there is a grid parallel to y ticks.
min_value (float) – Minimum value of param_axis.
max_value (float) – Maximum value of param_axis.
param_axis (str) – Axis opposite to index axis.
grid_minor_x (bool, optional) – When set to True, a minor grid is added to the plot along x axis.
grid_minor_y (bool, optional) – When set to True, a minor grid is added to the plot along y axis.
- rick.set_ticks(ax: axes, df: DataFrame, min_value: float, max_value: float, inc: float, index_axis: str = 'x', offset: float = 0.0, minor_x: bool = False, minor_y: bool = False, num_minor_x: int | None = None, num_minor_y: int | None = None) None [source]¶
Sets x and y axis tick locations and tick labels.
- Parameters:
ax (plt.axes) – Matplotlib axes object.
df (pd.DataFrame) – Dataset being plotted.
min_value (float) – Minimum value along non index axis.
max_value (float) – Maximum value along non index axis.
inc (float) – Incrementation of ticks along non index axis.
index_axis (str) – The index of the DataFrame object, e.g. the x axis for a line chart. Defaults to ‘x’.
offset (float) – Offset in the placement of ticks. Used for grouped bar charts to center labels. Defaults to 0.0.
minor_x (bool, optional) – When set to True, a minor grid is added to the plot along x axis.
minor_y (bool, optional) – When set to True, a minor grid is added to the plot along y axis.
num_minor_x (int, optional) – The number of minor ticks between major ticks along the x axis.
num_minor_y (int, optional) – The number of minor ticks between major ticks along the y axis.
- rick.vertical_bar_annotations(df: DataFrame, ax: axes, bar_width: float, upper: float, precision: int, percent: bool) None [source]¶
Adds value annotations to vertical grouped or regular bar charts.
- Parameters:
df (pd.DataFrame) – Input dataframe being plotted.
ax (plt.axes) – Axis object corresponding to the plot.
bar_width (float) – The width of each bar.
upper (float) – Bar value used for determining placement of annotation.
precision (int) – Decimal points in the annotations.
percent (bool) – Flag determining whether to show percentage change between baseline column (assumed to be the first column) and remaining columns.
Version 0.8.0
- gallery_lines.lines3(big_table, keys, other_silly_variable=None)[source]¶
Fetches rows from a Bigtable. See https://pythonhosted.org/an_example_pypi_project/sphinx.html (fetch_bigtable_rows(big_table, keys, other_silly_variable=None))
Retrieves rows pertaining to the given keys from the Table instance represented by big_table. Silly things may happen if other_silly_variable is not None.
- Parameters:
big_table – An open Bigtable Table instance.
keys – A sequence of strings representing the key of each table row to fetch.
other_silly_variable – Another optional variable, that has a much longer name than the other args, and which does nothing.
- Returns:
A dict mapping keys to the corresponding table row data fetched. Each row is represented as a tuple of strings. For example:
- {‘Serak’: (‘Rigel VII’, ‘Preparer’),
’Zim’: (‘Irk’, ‘Invader’), ‘Lrrr’: (‘Omicron Persei 8’, ‘Emperor’)}
If a key from the keys argument is missing from the dictionary, then that row was not found in the table.
- Raises:
IOError – An error occurred accessing the bigtable.Table object.
- gallery_lines.multi_linechart(df_lines, sett)[source]¶
Creates a line chart of one or more lines.
The number of lines to be plotted is automatically determined from the columns in the input dataframe. Also includes the option to display one or more shaded regions with labels.
- Parameters:
df_lines (pandas dataframe) – First column contains x-axis data, subsequent column(s) contain y-axis data.
sett (dict) – Styling and annotation specification for all visual elements (e.g. axes, grid, lines, legend, title, labels). If empty, defaults are used.
sett['body'] (dict key, optional) – Global style parameters for ‘font-size’, ‘font-family’, and ‘fontfamily-list’. If empty, defaults are used.
sett['body']['font-size'] (int, optional dict key) – Global font size for plot. Default 12.
sett['body']['font-family'] (str, optional dict key) – Global font family for plot. Default ‘sans-serif’.
sett['body']['fontfamily-list'] (array, optional dict key) – Array of fonts in font-family. The first font in the array that is installed in the system will be used. Default ‘Libre Franklin’.
sett['body']['stroke'] (hex str, optional dict key) – Global colour for lines and text. Default ‘#000000’.
sett['body']['stroke-width'] (num, optional dict key) – Global linewidth. Default 2.
sett['body']['border'] (str, optional dict key) – Global border style for lines. Default ‘solid’.
- Returns:
fig (Matplotlib fig object)
ax (Matplotlib ax object)