aaanalysis.plot_settings

aaanalysis.plot_settings(font_scale=1, font='Arial', weight_bold=True, adjust_only_font=False, adjust_further_elements=True, grid=False, grid_axis='y', no_ticks=False, short_ticks=False, no_ticks_x=False, short_ticks_x=False, no_ticks_y=False, short_ticks_y=False, show_options=False)[source]

Configure general plot settings.

This function modifies the global settings of matplotlib and seaborn libraries. It adjusts font embedding for vector formats like PDF and SVG, ensuring compatibility and editability across various viewers and editing software.

Added in version 0.1.0.

Parameters:
  • font_scale (int or float, default=1) – Scaling factor to scale the size of font elements. Consistent with seaborn.set_context().

  • font ({'Arial', 'Courier New', 'DejaVu Sans', 'Times New Roman', 'Verdana'}, default='Arial') – Name of text font. Common options are ‘Arial’ or ‘DejaVu Sans’ (Matplotlib default).

  • weight_bold (bool, default=True) – If True, font and line elements are bold.

  • adjust_only_font (bool, default=False) – If True, only the font style will be adjusted, leaving other elements unchanged.

  • adjust_further_elements (bool, default=True) – If True, makes additional visual and layout adjustments to the plot (errorbars, legend).

  • grid (bool, default=False) – If True, display the grid in plots.

  • grid_axis ({'y', 'x', 'both'}, default='y') – Choose the axis (‘y’, ‘x’, ‘both’) to apply the grid to.

  • no_ticks (bool, default=False) – If True, remove all tick marks on both x and y axes.

  • short_ticks (bool, default=False) – If True, display short tick marks on both x and y axes. Is ignored if no_ticks=True.

  • no_ticks_x (bool, default=False) – If True, remove tick marks on the x-axis.

  • short_ticks_x (bool, default=False) – If True, display short tick marks on the x-axis. Is ignored if no_ticks=True.

  • no_ticks_y (bool, default=False) – If True, remove tick marks on the y-axis.

  • short_ticks_y (bool, default=False) – If True, display short tick marks on the y-axis. Is ignored if no_ticks=True.

  • show_options (bool, default=False) – If True, show all plot runtime configurations of matplotlib.

Notes

  • grid_axis work only for axis with numerical values.

See also

Examples

A default seaborn barplot can be created as follows:

import matplotlib.pyplot as plt
import seaborn as sns
data = {'Classes': ['Class A', 'Class B', 'Class C'], 'Values': [23, 27, 43]}
sns.barplot(x="Classes", y="Values", data=data)
sns.despine()
plt.tight_layout()
plt.show()
../_images/plot_settings_1_output_1_0.png

Adjust plots with AAanalysis using aa.plot_settings():

import aaanalysis as aa
aa.plot_settings()
sns.barplot(x="Classes", y="Values", data=data)
sns.despine()
plt.tight_layout()
plt.show()
../_images/plot_settings_2_output_3_0.png

You can add our default colors using the aa.plot_get_clist() method:

colors = aa.plot_get_clist(n_colors=3)
sns.barplot(x="Classes", y="Values", data=data, palette=colors, hue="Classes")
sns.despine()
plt.tight_layout()
plt.show()
../_images/plot_settings_3_output_5_0.png

Adjust the font scale for all plot texts using a scaling factor called font_scale:

aa.plot_settings(font_scale=1.5)
sns.barplot(x="Classes", y="Values", data=data, palette=colors, hue="Classes")
sns.despine()
plt.tight_layout()
plt.show()
../_images/plot_settings_4_output_7_0.png

The font type and style can be adjusted by the font and weight_bold arguments:

aa.plot_settings(font="Times New Roman", weight_bold=False)
sns.barplot(x="Classes", y="Values", data=data, palette=colors, hue="Classes")
sns.despine()
plt.tight_layout()
plt.show()
../_images/plot_settings_5_output_9_0.png

If you only want to change the font type, you can set adjust_only_font=True:

aa.plot_settings(adjust_only_font=True, font="Arial")
sns.barplot(x="Classes", y="Values", data=data, palette=colors, hue="Classes")
sns.despine()
plt.tight_layout()
plt.show()
../_images/plot_settings_6_output_11_0.png

Grid can be enabled by grid=True and the grid-axis can be ‘x’, ‘y’, or ‘both’:

aa.plot_settings(grid=True, grid_axis="y")
sns.barplot(x="Classes", y="Values", data=data, palette=colors,
            hue="Classes")
sns.despine()
plt.tight_layout()
plt.show()
../_images/plot_settings_7_output_13_0.png

The x- any y-ticks can be easily adjusted. Remove all ticks by no_ticks=True:

aa.plot_settings(no_ticks=True)
sns.barplot(x="Classes", y="Values", data=data, palette=colors, hue="Classes")
sns.despine()
plt.tight_layout()
plt.show()
../_images/plot_settings_8_output_15_0.png

Or shorten all via short_ticks=True:

aa.plot_settings(short_ticks=True)
sns.barplot(x="Classes", y="Values", data=data, palette=colors, hue="Classes")
sns.despine()
plt.tight_layout()
plt.show()
../_images/plot_settings_9_output_17_0.png

This can as well be applied separately for the x- and y-axis:

aa.plot_settings(short_ticks_x=True, no_ticks_y=True)
sns.barplot(x="Classes", y="Values", data=data, palette=colors, hue="Classes")
sns.despine()
plt.tight_layout()
plt.show()
../_images/plot_settings_10_output_19_0.png