2015-05-29

Legible Plots with Matplotlib and LibreOffice

Have you ever struggled presenting scientific plots in LibreOffice? A lot of the time the fonts come out too small or it can happen that thin lines disappear in scaled figures. Often plots are not originally created to be shown on slides. A pragmatic solution to create more legible plots with Matplotlib for LibreOffice slides is to take the dimensions that a plot should have on the final slide into account when creating the plot.

LibreOffice offers 12 standard layouts, as can be seen below:
Not all of these layouts are suitable to present plots, but for those who are, the dimensions of the layout boxes should be taken into account to create legible plots. E.g. in Matplotlib this can be accomplished with the following command:

matplotlib.rc('figure', figsize= [width,height]) 

Moreover, it is advantageous to modify some other style options to make a plot more legible. Some style options which I found helpful in the past are the following:

matplotlib.rc('lines', linewidth=4.0) #thick lines
matplotlib.rc('font',  size=18) #big font

matplotlib.rcParams.update({'font.sans-serif': 'Liberation Sans'}) #adjust font w/ slide font

In my opinion .png is one of the few trustworthy output formats for plots. Generally producing plots in vector formats (e.g. .svg) would be nicer, but at least I have experienced these being rendered incorrectly (LibreOffice 4.3.6.2 was used at the time of this writing).

An example slide with these style options applied is shown below:

The full script that was used to create the sample plots can be downloaded here. It can also be used to create sample plots for the other LibreOffice layouts.

No comments:

Post a Comment