beautifulplots

Submodules

Package Contents

Functions

plot_defaults()

Dictionary of plot parameters. Each parameter coresponds and corresponding value.

set_axisparams(options_dict, ax, g)

Receives as input a dictionary of plot options and applies the options to the maxtplotlib axis and graph.

get_kwargs(**kwargs)

process **kwargs options corresponding to the plot_defaults dictionary (see above)

set_yaxis_format(ax[, yaxisformat, ycurrency, ...])

barplot(df, bar_columns, bar_values[, barcurrency, ...])

Bar plot function designed for ease of use and aesthetics.

lineplot

scatterplot

Attributes

__version__

beautifulplots.__version__
beautifulplots.plot_defaults()[source]

Dictionary of plot parameters. Each parameter coresponds and corresponding value. See also get_plot_options for extracting plot options from **kwargs.

Axis - x, y, and plot area parameters

Parameters
  • df (DataFrame) – The input DataFrame containing colums corresponding to bar values and columns.

  • title (String) – corresponds to the axis title. default = ‘’

  • title_fontsize – font size of the axis title, default = 18

  • x_lims – (xmin, xmax), minimum and maximum x-values of the axis. default = None, in which case the min and max are set automatically by matplotlib.

  • y_lims – (ymin,ymax), minimum and maximum y-values of the axis. default = None, in which case the min and max are set automatically by matplotlib.

  • y2_lims – (ymin,ymax), minimum and maximum y-values of the secondary axis. default = None, in which case the min and max are set automatically by matplotlib.

  • x_label_fontsize – default = 16

  • x_tick_labelsize – default = 16

  • x_tick_fontsize – default = 16

  • x_tick_rotation – default = 0

  • y_label_fontsize – ylabel font size, default = 16

  • y_tick_fontsize – xtick label font size, default = 16

  • y_tick_rotation – Rotation of the xtick label, default = 0

Plot attributes - Line, Bar, Scatter Plots

Parameters
  • marker – Matplotlib line markers. default = None (Matplotlib default).

  • marker2 – Secondary axis, Matplotlib line marker. default = None (Matplotlib default).

  • marker – sns line markers. default = None (sns default).

  • marker2 – Secondary axis, sns line markers. default = None (sns default).

  • y_axis_currency (Boolean) – Boolean default = False.

  • y_tick_format (String) – String default = None (Matplotlib default).

  • alpha (fraction) – Trasnparancy (opacity), default = None (not transparent)

  • alpha2 (fraction) – Secondary axis, default = 0.5, 50% opacity

  • legend_labels (list) – Overide default legend labels. default = None (do not override)

  • legend_loc (String) – Matplotlib legend location, for example, upper right , default = “best”.

  • legend_loc2 (String) – Secondary axis legend location, for example, upper right , default = best.

  • legend_fontsize – legend font size, default = 16

  • estimator – seaborn barplot summary estimator, default = sum

  • estimator2 – secondary axis, seaborn barplot summary estimator, default = sum

  • color – default = None, indicateing Matplolib default (Matplotlib default)

  • color2 – secondary axis line, bar or color. defualt = None (Matplotlib default)

  • palette – colormap, default = None

  • palette2 – colormap, default = None, secondary y axis.

  • hue – dimension value for corresponding Seaborn graphs, default = None.

  • errorbar – Seaborn errorbar parameter: float, sd, or None

  • errorbar2 – Seaborn errorbar parameter second y axis: float, sd, or None

  • x_label (String) – xlabel title, default = ‘’

  • y_label (String) – y lable title, default = ‘’

  • h_line (int) – y-value, corresponding to horizontal line, default = None

  • h_line_label (String) – y value, corresponding to horizontal line, default = None

  • v_line (int) – x-value, corresponding to vertical line, default = None (no line)

  • v_line_label (String) – x value, corresponding to vertical line, default = None (no line)

  • y_scale (String) – scale for the y-axis (e.g., yscale = “log”), default = None (default is linear)

  • x_scale (String) – scale for the x-axis (e.g., xscale = “log”), default = None (default is linear)

Plots and subplots

Parameters corresponding to the plot or subplot characteristics. They are used when matplot_helpers functions create the plot figure and axis, otherewise, these parameters do not affect the plot.

Parameters
  • plot_style (String) – matplotlib plot style

  • fig_size – total size (height, width) in inches of the figure, including total plotting area of all subplots and spacing

  • w_space – width space (horizontal) between subplots, default wspace = 0.2

  • h_space – height space (vertical) between subplots, default hspace = 0.2

Annotations

Parameters
  • annotate (List of Strings and positions) – default = None. List of Strings with corresponding (x,y) positions.

  • annotate_fontsize (int) – default = 16. Fontsize for each annotation.

Returns

Dictionary: {parameter1:value1, parameter2:value2, … }. Pairs of plat parameters and corresponding values.

beautifulplots.set_axisparams(options_dict, ax, g)[source]

Receives as input a dictionary of plot options and applies the options to the maxtplotlib axis and graph.

Parameters
  • options_dict (dictionary) – dictionar containint plot options. Each key, value pair corresponds to a plot parameter

  • ax (axis) – matplotlib axis to apply the plot options

  • g (graph) – matplotlib graph to apply the plot options

Returns

returns None if the function completes without errors.

Return type

None

beautifulplots.get_kwargs(**kwargs)[source]

process **kwargs options corresponding to the plot_defaults dictionary (see above) If a beautifulplots plot_option dictionary key is contained in the **kwargs then the plot_defautls[key] value is replaced with that found in **kwargs.

Returns

{parameter1:value1, parameter2:value2, …} dictionary corresponding to plot options

Return type

Dictionary

beautifulplots.set_yaxis_format(ax, yaxisformat='1.2f', ycurrency=None, labelcolor='black', which='major')[source]
beautifulplots.barplot(df, bar_columns, bar_values, barcurrency=None, barorientation='v', bardataformat='1.2f', y2=None, estimator=sum, estimator2=sum, ax=None, bardatalabels=False, test_mode=False, bardatafontsize=14, **kwargs)[source]

Bar plot function designed for ease of use and aesthetics. The underlying barplot is ased on the Seaborn with additions, such as secondary axis, data labels, and improved default parameters. Refer to beautifulplots plot_defaults for a complete list of options.

Parameters
  • df (DataFrame) – The input DataFrame containing colums corresponding to bar_plot values (“bar_values”) and column names (see examples in documentation)

  • bar_columns – Datafrae columns corresponding to bar column names

  • bar_values – Dataframe column corresponding to bar column values

  • ax (axis) – matplotlib axis (optional), default = None. If axis is None, then create a matplolib figure, axis to host the barplot

  • color – Matplotlib compatabile color name as text or RGB values, for example, color = [51/235,125/235,183/235].

  • palette – Matplotlib compatible color palette name, for example, “tab20”

  • hue – Name of hue dimension variable (i.e., DataFrame column name)

  • ci – Seaborn confidence interval parameter: float, sd, or None, default = None

  • barorientation – default = v (vertical), or h (horizontal)

  • barcurrency – default = False (bar values do not represent currency). True (bar values represent currency, append $ to the value)

  • bardatalabels (Boolean) – default = False (data labels not included)

  • estimater – default = sum. Specifies how to aggregate plot bar data.

  • estimator2 – default = None. Summarize y2 asis daa. Default is no aggregation, do not summarize y2 axis data.

  • options (additional) – see beautifulplot.plot_defaults for additional input variables.

Returns

returns True if processing completes succesfully (without errors).

beautifulplots.lineplot(df, x, y, y2=None, ax=None, test_mode=False, estimator=None, estimator2=None, **kwargs)[source]

Lineplot function designed for ease of use and aesthetics. Based on the Seaborn lineplot, with additions such as secondary axis, ease of use, and improved default parameters. Refer to beautiful plot_defaults for full list of options.

Parameters
  • df (Dataframe) – The input DataFrame containing colums corresponding to x and y

  • x – Dataframe column corresponding to the lineplot x-axis aldfsd;lfj

  • y – Dolumn or list of columns corresponding to the lineplot y-axis

  • y2 – Column or list of columns correspondng to the secondary axis, default = None

  • yaxisformat – default = “1.2f”

  • ycurrency – default = None. Primary y-axis. For example = “$” to prepend dollar symbol.

  • y2currency – default = None. Secondary y-axis. For example = “$” to prepend dollar symbol.

  • marker – default = None. Primary y-axis. Matplotlib line marker. If y is a list, then marker must be a list of markers.

  • marker2 – default = None. Secondary y-axis. Matplotlib line marker. If y2 is a list, then marker2 must be a list of markers.

  • estimator – Specifies how to summarize data corresponding to y-axis. Defaults to plot all data points do not summarize.

  • estimator2 – Specifies how to summarize data corresponding to y2-axis. Defaults to plot all data points do not summarize.

  • options (additional) – see beautifulplot.plot_defaults for additional input variables.

Returns

returns None if processing completes succesfully (without errors).

beautifulplots.scatterplot(df, x, y, ax=None, test_mode=False, **kwargs)[source]

Scatterplot function. The underlying barplot is ased on the Seaborn with additions, such as data labels, and improved default parameters. Refer to beautifulplots plot_defaults for a complete list of options.

Parameters
  • df (DataFrame) – The input DataFrame containing colums corresponding to bar_plot values (“bar_values”) and column names (see examples in documentation)

  • x – Dataframe column corresponding to the x-axis

  • y – Column or list of columns corresponding to the y-axis

  • ax (axis) – matplotlib axis (optional), default = None. If axis is None, then create a matplolib figure, axis to host the barplot

  • color – default = None (Matplotlib default). Matplotlib compatabile color name as text or RGB values, for example, color = [51/235,125/235,183/235].

  • palette – Matplotlib compatible color palette name, for example, “tab20”

  • hue – Name of hue dimension variable (i.e., DataFrame column name)

  • options (additional) – see beautifulplot.plot_defaults for additional input variables.

Returns

returns True if processing completes succesfully (without errors).