Sto cercando di cambiare il tipo di carattere matplotlib a helvetica, che mi piacerebbe utilizzare in una trama PDF. Provo il seguente:non può cambiare tipo di carattere Helvetica in Matplotlib in Python su Mac OS X 10.6
import matplotlib
matplotlib.use('PDF')
import matplotlib.pylab as plt
from matplotlib import rc
plt.rcParams['ps.useafm'] = True
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
plt.rcParams['pdf.fonttype'] = 42
Questo non funziona - quando ho eseguito il mio codice con --verbose-debug, ottengo l'errore:
backend WXAgg version 2.8.10.1
/Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/matplotlib/__init__.py:833: UserWarning: This call to matplotlib.use() has no effect
because the the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.
findfont: Could not match :family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=medium. Returning /Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf
Assigning font /F1 = /Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf
Embedding font /Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf
Writing TrueType font
Quindi a quanto pare non riesce a trovare Helvetica. Non sono sicuro del perché. Ho Helvetica nella directory AFM di MPL-dati, e quando matplotlib avvia lo legge e uscite:
createFontDict: /Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/matplotlib/mpl-data/fonts/afm/Helvetica.afm
Ho bisogno di una speciale .ttf font Helvetica in aggiunta? Se è così, come posso ottenerlo? So di avere Helvetica sul mio sistema da quando lo vedo in Illustrator e in molti altri programmi.
Sto usando la distribuzione Enthought Python come segue:
$ python
Enthought Python Distribution -- http://www.enthought.com
Version: 6.2-2 (32-bit)
Python 2.6.5 |EPD 6.2-2 (32-bit)| (r265:79063, May 28 2010, 15:13:03)
[GCC 4.0.1 (Apple Inc. build 5488)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.__version__
'0.99.3'
Tutte le idee come questo può essere fissato?
grazie.
Grazie per avermi fatto la domanda e aver risposto - sono sicuro che questo mi sarà utile qualche volta, e questo è esattamente il genere di cosa per cui è stato creato StackOverflow. – ShreevatsaR
Potresti fornire maggiori dettagli? La soluzione passo passo di Max Malysh funziona come un fascino! – meduz