mpl_bsic.check_figsize#

mpl_bsic.check_figsize(width=None, height=None, aspect_ratio=None)[source]#

Check the validity of the figsize.

Checks the validity of the figsize parameters and returns the width and height you should use for the plot. You must specify at least two of the three parameters, otherwise the function will return an error.

When exporting plots for a word document, Word will resize the image automatically if it doesn’t fit the page. This will cause the font sizes to be inconsistent across the article and the graph, with the title of the plot being smaller than the usual style of the sections. To avoid this, you must make sure that the width of the plot is less than 7.32 inches, which is the width of a word document available for figures.

This function makes sure that you respect the guidelines for the image size, so that it won’t be later resized by Word and the font sizes will be consistent.

Parameters:
widthfloat | None

Width of the Figure, in inches.

heightfloat | None

Height of the Figure, in inches.

aspect_ratiofloat | None

Aspect Ratio of the figure, as a float. E.g. 16/9 for 16:9 aspect ratio.

Returns:
tuple[float, float]

The correct width and height to use for the Figure.

See also

apply_bsic_style.apply_bsic_style

The function that applies the style to the plot.

mpl_bsic.preprocess_dataframe

The function that preprocesses the DataFrame before plotting.

Examples

>>> check_figsize(5, 3) # with correct width and height
(5, 3)

If the width is too large, it will be resized to fit a word document, while keeping the original aspect ratio constant.

>>> check_figsize(10, 5) # width > 7.32
Width is greater than 7.32 inches.
This is the width of a word document available for figures.
If you set the width > 7.32, the figure will be resized in word and
the font sizes will not be consistent across the article and the graph
(7.32, 3.66)

You can also only specify width/height and aspect ratio, and the other will be computed. Again, if the width is too large, it will be resized to fit a word document.

>>> check_figsize(5, aspect_ratio=16/9) # provide width and aspect ratio
(5, 2.8125)
>>> check_figsize(10, aspect_ratio=16/9) # width is too large
Width is greater than 7.32 inches (the max length of a word document).
Setting width to 7.32 inches.
(7.32, 4.1175)
>>> check_figsize(height=3, aspect_ratio=16/9)
(5.33, 3)