Figure management functions

Page setup

This is the main function that have to be called everytime the library is used.

matplotlib_latex_bridge.setup_page(textwidth, columnwidth, fontsize, dpi=400, usetex=True)

Setup the page defaults

Using LaTex to render text requires a working LaTeX installation.

Parameters
  • textwidth – width of the text in inches

  • columnwidth – widht of the line (column) in inches

  • fontsize – default font size of the document

  • dpi – dpi for generated images

  • usetex – True if the LaTeX processor should be enabled to render text

Font control

To fine tune the font control, these functions can be called after matplotlib_latex_bridge.setup_page().

matplotlib_latex_bridge.set_font_sizes(small=8, medium=10, big=12)

Set the default fonts for the figures

Usually the medium size should correspond to the normal latex text font size.

The small and big sizes can be omitted, and they will be computed according to the medium size.

Parameters
  • small – used for ticks and legends

  • medium – used for the labels of the axes

  • big – used for plot titles

matplotlib_latex_bridge.set_font_family(family='serif', usetex=True)

Set the default font to match latex

Using LaTex to render text requires a working LaTeX installation.

Parameters
  • family – font family used in the document

  • usetex – True if the LaTeX processor should be enabled to render text

Figure control

The default figure size can be changed or accessed after the initial setup by using these functions.

matplotlib_latex_bridge.set_default_figsize(w=None, h=None, dpi=400)

Set the default figure size

This is the size that will be used by doing plt.figure().

Parameters
  • w – width

  • h – height

  • dpi – dpi

matplotlib_latex_bridge.get_default_figsize()

Return the current figure size defaults

Returns

default width, default height

Figure generation

These functions allow the creation of matplotlib figures using (or overriding) the default size specified in the initial setup.

matplotlib_latex_bridge.figure_columnwidth(widthp=1.0, height=None, **kwargs)

Creates a figure that fill the width of the line (column)

Parameters
  • widthp – width of the figure as a percentage of the line width (between 0 and 1)

  • height – height of the figure (optional)

  • kwargs – arguments that will be forwarded to matplotlib.pyplot.figure()

Returns

the new figure (matplotlib.figure.Figure)

matplotlib_latex_bridge.figure_textwidth(widthp=1.0, height=None, **kwargs)

Creates a figure that fill the width of the page

Parameters
  • widthp – width of the figure as a percentage of the text width (between 0 and 1)

  • height – height of the figure (optional)

  • kwargs – arguments that will be forwarded to matplotlib.pyplot.figure()

Returns

the new figure (matplotlib.figure.Figure)

matplotlib_latex_bridge.figure(width=None, height=None, **kwargs)

Creates a figure with a custom size

This function will print a warning if the figure width exceeds the width of the page or the line.

Parameters
  • width – width of the figure (optional)

  • height – height of the figure (optional)

  • kwargs – arguments that will be forwarded to matplotlib.pyplot.figure()

Returns

the new figure (matplotlib.figure.Figure)

Getting format from LaTeX

This function can be used to get format informations directly from LaTeX, but requires a working LaTeX installation.

matplotlib_latex_bridge.get_format_from_latex(documentclass, columns=None, papersize=None, fontsize=None, otheroptions=None)

Get the format by invoking the LaTeX processor

This functions compiles a sample file with the LaTeX processor and parse its output to get information about text and column widths and fontsize.

The output of this function can be directly used to setup the page.

Using this function requires a working LaTeX installation.

Parameters
  • documentclass – layout standard to use (ex. article, report, book, …)

  • columns – number of columns (ex. twocolumn)

  • papersize – size of the paper (ex. a4paper, letterpaper, …)

  • fontsize – size of the font (ex. 10pt, 11pt, 12pt)

  • otheroptions – comma-separated additional options

Returns

dictionary with textwidth, columnwidth and fontsize