I have matplotlib figures with labels, which are included as PDF in LaTeX document. I would like label text match with the font of the text, which is concrete (via \usepackage{concrete}).

I can change math font in labels with

import matplotlib as mpl

but adding \usepackage{concrete} has no effect on the text font (probably since the default Helvetica is used regardless). usetex documentation does not mention concrete to be supported directly.

I also have the cm-unicode opentype variants of CMU fonts (CMU Concrete) installed, in case that could be of any use.


This does not answer your question directly, but is perhaps a possible workaround:

As I mentioned in Set fonts in matplotlib graphs equal to tex document you can perhaps export your plot with the script matplotlib2tikz. This gives you a .tex file with a TikZ/pgfplots figure that can be input in your document. This will use the same fonts as the document.

Edit: For reference, here is a brief explanation of installation and use.

Having downloaded the files from github, navigate to the folder in a command line, and run python setup.py install to install matplotlib2tikz.

In your Python script add from matplotlib2tikz import matplotlib2tikz, and add matplotlib2tikz('filename.tex') after your plot, e.g.

from numpy import arange
from matplotlib2tikz import matplotlib2tikz
import matplotlib.pyplot as plt

x = arange(0,10,0.5)

plt.title("A lovely plot")

You can also specify the width and height of the plot in the Python script, as mentioned in the readme of matplotlib2tikz.

| improve this answer | |
  • Very nice! In addition, it will work with any possible fonts. Thanks. – eudoxos Nov 2 '11 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.