You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to set multiple default fonts with matplotlib? #3010
I asked this as a SO question that didn't seem to get any responses.
I don't think this is a bug, but it feels like a bug because I don't understand it :). Feel free to close this and answer over there if you think it is just a misunderstanding.
I want to set the default matplotlib fonts through the rc parameters in a way that is portable to computers that might not have the same set of fonts available.
Here is what I thought would work:
importmatplotlibasmplimportmatplotlib.pyplotaspltmpl.rcParams["font.sans-serif"] = ["Arial", "Liberation Sans", "Bitstream Vera Sans"]
mpl.rcParams["font.family"] ="sans-serif"ax=plt.subplot()
ax.plot([0, 1, 2], [0, 2, 1])
ax.set_xlabel("the x label")
Because I have Arial installed on my system, I thought that the xlabel would be in Arial. But this approach should mean the default for someone who doesn't have Arial but does have Liberation Sans (i.e. a default Ubuntu system) will be Liberation Sans. And then it should fall back to Bitstream Vera Sans as the default when neither of the two alternate choices are available.
However, this is not what happens. If I do print ax.xaxis.label.get_fontname() it reports Bitstream Vera Sans. Again, I have Arial installed. In other words, I can then do
ax.set_ylabel("the y label", fontdict={"name": "Arial"})
printax.yaxis.label.get_fontname()
and get Arial.
It feels like I am missing something fundamental about the relationship between the font.family rc parameter and the font.sans-serif parameter when family is "sans serif".
I think the problem you are running into is solved by #2771 -- which has stalled out because we're having trouble getting the test suite to pass on Travis with those changes. We'll need to devote a few cycles to getting that resolved -- but you could try using that patch locally if you want it today.
So I'm a little confused, is this is a bug just on 1.3.1, or on anything <= 1.3.1? I'm trying to figure out the best way to work around this in seaborn.
[matplotlib]{master}$ pip install .
Unpacking /Users/mwaskom/Code/matplotlib
Running setup.py egg_info for package from file:///Users/mwaskom/Code/matplotlib
============================================================================
Edit setup.cfg to change the build options
BUILDING MATPLOTLIB
matplotlib: yes [1.4.x]
python: yes [2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Jan
10 2014, 11:23:15) [GCC 4.0.1 (Apple Inc. build
5493)]]
platform: yes [darwin]
REQUIRED DEPENDENCIES AND EXTENSIONS
numpy: yes [version 1.8.1]
six: yes [using six version 1.6.1]
dateutil: yes [using dateutil version 2.2]
tornado: yes [using tornado version 3.2]
pyparsing: yes [using pyparsing version 2.0.1]
pycxx: yes [Couldn't import. Using local copy.]
libagg: yes [pkg-config information for 'libagg' could not
be found. Using local copy.]
freetype: no [The C/C++ header for freetype2 (ft2build.h)
could not be found. You may need to install the
development package.]
png: yes [pkg-config information for 'libpng' could not
be found. Using unknown version.]
qhull: yes [pkg-config information for 'qhull' could not be
found. Using local copy.]
OPTIONAL SUBPACKAGES
sample_data: yes [installing]
toolkits: yes [installing]
tests: yes [using nose version 1.3.0 / mock is required to
run the matplotlib test suite. pip/easy_install may
attempt to install it after matplotlib.]
OPTIONAL BACKEND EXTENSIONS
macosx: yes [installing, darwin]
qt4agg: no [PyQt4 not found]
gtk3agg: no [Requires pygobject to be installed.]
gtk3cairo: no [Requires cairocffi or pycairo to be installed.]
gtkagg: no [Requires pygtk]
tkagg: yes [installing, version 81008]
wxagg: no [requires wxPython]
gtk: no [Requires pygtk]
agg: yes [installing]
cairo: no [cairocffi or pycairo not found]
windowing: no [Microsoft Windows only]
OPTIONAL LATEX DEPENDENCIES
dvipng: yes [version 1.14]
ghostscript: no
latex: yes [version 3.1415926]
pdftops: no
============================================================================
* The following required packages can not be built:
* freetype
Complete output from command python setup.py egg_info:
============================================================================
Edit setup.cfg to change the build options
BUILDING MATPLOTLIB
matplotlib: yes [1.4.x]
python: yes [2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Jan
10 2014, 11:23:15) [GCC 4.0.1 (Apple Inc. build
5493)]]
platform: yes [darwin]
REQUIRED DEPENDENCIES AND EXTENSIONS
numpy: yes [version 1.8.1]
six: yes [using six version 1.6.1]
dateutil: yes [using dateutil version 2.2]
tornado: yes [using tornado version 3.2]
pyparsing: yes [using pyparsing version 2.0.1]
pycxx: yes [Couldn't import. Using local copy.]
libagg: yes [pkg-config information for 'libagg' could not
be found. Using local copy.]
freetype: no [The C/C++ header for freetype2 (ft2build.h)
could not be found. You may need to install the
development package.]
png: yes [pkg-config information for 'libpng' could not
be found. Using unknown version.]
qhull: yes [pkg-config information for 'qhull' could not be
found. Using local copy.]
OPTIONAL SUBPACKAGES
sample_data: yes [installing]
toolkits: yes [installing]
tests: yes [using nose version 1.3.0 / mock is required to
run the matplotlib test suite. pip/easy_install may
attempt to install it after matplotlib.]
OPTIONAL BACKEND EXTENSIONS
macosx: yes [installing, darwin]
qt4agg: no [PyQt4 not found]
gtk3agg: no [Requires pygobject to be installed.]
gtk3cairo: no [Requires cairocffi or pycairo to be installed.]
gtkagg: no [Requires pygtk]
tkagg: yes [installing, version 81008]
wxagg: no [requires wxPython]
gtk: no [Requires pygtk]
agg: yes [installing]
cairo: no [cairocffi or pycairo not found]
windowing: no [Microsoft Windows only]
OPTIONAL LATEX DEPENDENCIES
dvipng: yes [version 1.14]
ghostscript: no
latex: yes [version 3.1415926]
pdftops: no
============================================================================
* The following required packages can not be built:
* freetype
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /var/folders/rr/svlz5yhs0tsdqnsp8g4qg65m0000gn/T/pip-beHCX1-build
Apparently I have freetype 2.4.10 installed, according to conda.
Offhand, it seems like the problem is related overwriting the Anaconda matplotlib with the one you are building with pip. I think I would try to restore a clean Anaconda, and then build and install in some other location. I suppose a virtualenv could be used for this, or maybe the --user option to pip install. That's just a rough outline; I don't know what the best method would be in detail.
Activity
mdboom commentedon Apr 28, 2014
I think the problem you are running into is solved by #2771 -- which has stalled out because we're having trouble getting the test suite to pass on Travis with those changes. We'll need to devote a few cycles to getting that resolved -- but you could try using that patch locally if you want it today.
mwaskom commentedon May 8, 2014
So I'm a little confused, is this is a bug just on 1.3.1, or on anything <= 1.3.1? I'm trying to figure out the best way to work around this in seaborn.
mdboom commentedon May 8, 2014
I think it was introduced in 1.3.0 and will be fixed in the next release.
mwaskom commentedon May 8, 2014
Is there an ETA on 1.4? And will there be a 1.3.x bugfix release?
tacaswell commentedon May 9, 2014
'soon' for 1.4 and probably not on 1.3.2.
tacaswell commentedon May 17, 2014
@mwaskom Can you confirm that this is fixed for you an master?
mwaskom commentedon May 17, 2014
I am unable to build matplotlib on my laptop :(
Apparently I have freetype 2.4.10 installed, according to conda.
tacaswell commentedon May 17, 2014
Does this PR help? #3032
mwaskom commentedon May 17, 2014
Well, with that I can install matplotlib but not import it
tacaswell commentedon May 17, 2014
I guess that is progress? @maciejkula can you take a look at this? iirc @efiring is a mac user. Do we have a local anaconda expert?
efiring commentedon May 17, 2014
Offhand, it seems like the problem is related overwriting the Anaconda matplotlib with the one you are building with pip. I think I would try to restore a clean Anaconda, and then build and install in some other location. I suppose a virtualenv could be used for this, or maybe the --user option to pip install. That's just a rough outline; I don't know what the best method would be in detail.
mwaskom commentedon May 17, 2014
The example in the first post should be sufficient to test for anyone who has Arial (or Liberation Sans) installed and is using master.
tacaswell commentedon May 17, 2014
Closing this as that example works correctly for me on current master.