Skip to content

Latest commit

 

History

History
97 lines (70 loc) · 3.15 KB

README.md

File metadata and controls

97 lines (70 loc) · 3.15 KB

physrev_mplstyle

Introduction

This is a Matplotlib style sheet designed to help one produce publication-quality figures for the APS Physical Review journals easily. In particular:

  • It uses Computer Modern as font.
  • It sets axes and tick labels font sizes to match that of revtex4-2's default 10pt. Labels have some "breathing" space from the figure's frame.
  • Figure's width is set as to use of most of the column-width space available when using the double-column format.
  • Figure's heigth is such that width / height ~ golden ratio.
  • Uses Mathematica's default color palette for up to nine colours.
  • Has the option to use gnuplot's default color palette for up to eight colours.
  • Has additional tweaks to the default legend, grid and line styles.

Usage

See the example notebook plt.ipynb. First, save physrev.mplstyle somewhere in your computer and use as preamble:

import matplotlib.pyplot as plt

%matplotlib inline
%config InlineBackend.figure_format='retina' # Optional

plt.style.use('physrev.mplstyle') # Set full path to if physrev.mplstyle is not in the same in directory as the notebook
plt.rcParams['figure.dpi'] = "300"

The line plt.rcParams['figure.dpi'] = "300" is for convenience; it makes the otherwise small-sized figure appear larger when printed out in the notebook.

A basic example is the following:

f, ax = plt.subplots(1, 1)

x = np.linspace(0, 1)
s = np.flip(np.arange(1, 1 + 9/10., 1/10.))

for slope in s:
    ax.plot(x, slope * x, label="{:0.1f}".format(slope))

ax.set_xlim(0, 1);
ax.set_ylim(0, 2);

ax.set_xlabel(r'$x$')
ax.set_ylabel(r'$y = s \, x$')

ax.legend(ncol=3)
ax.get_legend().set_title(r"Values of $s$")  
ax.grid()

plt.savefig('tmp.pdf')

This produces the following figure:

We can now use this image in a tex document. Usually, my documentclass has:

\documentclass[aps, 10pt, prd,
               notitlepage, twocolumn, superscriptaddress,
               longbibliography,
               nofootinbib, floatfix]{revtex4-2}

and we can insert our figure as

\begin{figure}[htb]
  \includegraphics[width=\columnwidth]{figs/tmp.pdf}
  \caption{Example of figure in a document using \texttt{revtex4-2}.}
  \label{fig:tmp}
\end{figure}

And that's it.

To use the gnuplot colour palette, comment line 9 in physrev.mplstyle and uncomment line 13. Here is an example:

Resources for the plotting aficionado

  • Matplotlib documentation on customization.
  • See also my previous style sheets at the mplstyle repo.
  • You may be interested in checking also SciencePlots package.