1

I am creating a scatter plot with color map based on some values and I am trying to make part of the x_axis label italic (inspired mostly by this post -> https://stackoverflow.com/a/8384685/1093485) but I am getting a LaTeX error that I can not explain myself, I would appreciate if anyone is able to explain what is going wrong with this chunk?

Minimum code required to reproduce problem here:

#! /usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
X = [1257.422648,1298.449197,1339.475746,1419.475471,1455.52309,1460.50202,1485.533655]
Y = [21.84637515,18.19617016,22.29456694,5.228978612,3.888695726,12.36598466,4.201838517]
Z = [44.02797944,9.758071204,21.58997772,64.53887544,53.09630431,8.461254471,291.4311435]

# Enable LaTeX style                
rc('text',usetex=True)

# Plot the data
fig=plt.figure()
fig.patch.set_facecolor('white')
ax=fig.add_subplot(111)
s = ax.scatter(X,Y,c=np.log(Z))
ax.set_xlabel(r'Analyte \textit{m/z}')
ax.xaxis.labelpad = 7.5
cb = plt.colorbar(mappable=s,ax=ax)

plt.show()

Commenting the rc('text',usetex=True) causes the plot to show but obviously without italics. The whole traceback is rather large but seems to revolve around this part (if I read it correctly):

RuntimeError: LaTeX was not able to process the following string:
'$1450$'

Anyone have a suggestion on what to do to isolate the problem?

Community
  • 1
  • 1
Bas Jansen
  • 3,273
  • 5
  • 30
  • 66
  • 1
    Your example works fine on my machine (python 2.7.7, matplotlib 1.3.1) - do you have a current mpl-version? I had issues with different backends in the past, you might want to try something like ``matplotlib.use("Qt4Agg")``. I also had problems with updating, which could be resolved by wiping the ``.matplotlibrc`` directory. Furthermore, ensure your LaTeX installation works, e.g. ``ax.set_xlabel("$x$")`` – Dietrich Jun 28 '14 at 09:35
  • I get no different result with `matplotlib.use("Qt4Agg")` and the `ax.set_xlabel("$x$")` yields a similar error. Synaptics tells me that I have texlive-latex-base 2009-15 installed on my system and I have used it with texmaker before (to write some documentation). – Bas Jansen Jun 30 '14 at 08:57
  • It looks like an installation problem, probably with matplotlib. You can try to update to current versions (python 2.7.7, matplotlib 1.3.1) or use a debugger to see what happens under the hood. – Dietrich Jun 30 '14 at 18:11
  • The error arises at the `plt.show()` according to `pdb`, that is all I can say for now. – Bas Jansen Jul 01 '14 at 15:00

0 Answers0