0

I'm trying to use the latex symbol \odot as a marker in a scatter plot but I also need latex style ticks, but for some reason these two are not playing well together. I can successfully use marker=$\\odot$ with usetex=False, like this, but when I set it equal to true (to get the tick font right), I get ! LaTeX Error: File 'type1cm.sty' not found. I've already gone through to make sure I have the sty file installed and in the correct directory and that I have all the dependencies installed (as suggested here). Plus, I can still have usetex=True and use any of the normal pyplot markers, just not anything involving math font, but can I can have \odot in the label for the legend. Ive also already tried appending the rc params with amsmath but still keep getting the type1cm error. I've also tried using the raw string literal to no avail.

So basically when usetex=True, I can use math symbols in the label for the legend, just not as the actual marker. Has anyone experienced this issue before?

My current work around involves just plotting a large unfilled circle and overplotting a small filled circle (basically simulating the odot). Then I run into an issue with the legend so I basically have to create a transparent legend showing the large unfilled circles and then plot the smaller filled circles behind it by hand like this which ends up wonky, but this has the axes tick font I need. This becomes very frustrating if I have to change axes limits though, because I have to repeat the process of figuring out where to plot the small filled circles all over again.

Does anyone know if there is a better work around than this? Would it be possible to use the overplotting scheme like I have been, but then create a custom proxy artist to display the \odot symbol (in the different colors/sizes) in the legend?

Mac OSX, matplotlib 1.4.2, python 2.7, matplotlib is using pdfTeX thru TeX Live 2017/Mac Ports 2017

Edit: Here is my code

plt.rc('text', usetex=True)
plt.rc('font', family='serif')

f, ax1 = plt.subplots(1,1)
x = np.arange(20)
y = x

ax1.scatter(x, y, marker='$\\odot$', edgecolors='b', s=200, label = 'Test') #used with usetex=False
#ax1.scatter(x, y, marker='o', edgecolors='b', s=200, label = 'Test') #used with usetex=True


ax1.tick_params(labelsize=24)
leg = ax1.legend(scatterpoints=1,  loc='lower right', borderaxespad=0., handletextpad=0.)#, fontsize=18) # borderpad=0.,)
Courtney
  • 15
  • 4
  • Would it be an option to update matplotlib? It seems your version is rather old. I don't know if this will solve the issue though, because it might acutally depend on your tex install. As for a workaround, what exactly is the reason you need to use latex? Maybe you can just use a font which looks similar to the latex font you have in mind? (See e.g. [this question](https://stackoverflow.com/questions/42249945/matplotlib-2-inconsistent-font)) – ImportanceOfBeingErnest Oct 06 '17 at 08:56
  • I need to have the latex formatted ticks to be consistent with some of my other plots. What font would emulate the latex style? Will setting the font to that change the tick? – Courtney Oct 06 '17 at 16:04
  • Tried creating a new conda env with updated matplotlib 2.0.2 and still have same results. – Courtney Oct 06 '17 at 16:48

1 Answers1

0

I'm not sure how much I can help without seeing your code, but this worked for me:

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

x1 = [1,2]; x2 = [1,2]
y1 = [1,1]; y2 = [2,2]

mpl.rc('text', usetex = True)
fig, ax = plt.subplots(1,1)
ax.scatter(x1,y1, label='A1', marker=r'$\odot$',s=150, c='b')
ax.scatter(x2,y2, label='A2', marker=r'$\odot$',s=50, c='b')
ax.set_xlim(0,3)
ax.set_ylim(0,3)
ax.legend()
fig.show()

enter image description here

If this doesn't help let me know!

Robbie
  • 4,672
  • 1
  • 19
  • 24
  • My code looks almost exactly like this. I edited my question above to include what I have. I've tried `marker=r'$\odot$'`, `='$\odot$'`, `=r'$\\odot$`, and `='$\\odot$'` and all give the same `type1cm.sty file not found` when `usetex-True`. I've also tried all the different commands of setting `usetex=True` and also have tried having a separate matplotlibrc file in my working directory with `usetex=True` and everything still gives the type1cm error when I use `\odot` as a marker. – Courtney Oct 06 '17 at 16:54