Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request : could the default windows font of matplotlib support an utf-8 "µ" ? #2397

Closed
stonebig opened this issue Sep 9, 2013 · 6 comments

Comments

@stonebig
Copy link
Contributor

stonebig commented Sep 9, 2013

Hello,

In Default Matplotlib the "latin1" µ prints well, but the "utf-8" µ apparently doesn't.
Would it be possible to be 'by default' , on windows in
plt.rc('font', **{'sans-serif' : 'Arial', 'family' : 'sans-serif'})

** sample code and post explaining the problem **

-- coding: utf-8 --

from matplotlib import pyplot as plt

plt.plot([1,2],[3,4])

change the default matplotlib font, that doesn't print the utf-8 µ !

the 'well-known' latex definition $\mu$ works perfect in any case

ref :http://stackoverflow.com/questions/10960463/non-ascii-characters-in-matplotlib

plt.rc('font', **{'sans-serif' : 'Arial', 'family' : 'sans-serif'})

plt.xlabel("A distance (μm) (or $\mu$m)")

plt.show()

@mdboom
Copy link
Member

mdboom commented Sep 9, 2013

The error message says:

ValueError: matplotlib display text must have all code points < 128 or use Unicode strings

You are using a regular 8-bit string (assuming you are on Python 2).

You should instead use a Unicode string:

plt.xlabel(u"A distance (μm) (or $\mu$m)")

@mdboom mdboom closed this as completed Sep 9, 2013
@stonebig
Copy link
Contributor Author

Hi,

I'm on a python3.3 windows 32bit (vista) installation. (winpython 3.3.2.3 precisely)
I removed the "u" because it is meaningless under python3.

Re-doing more carefully the test

  • I see there is also an error message in the python console , when, and only when, I put in comment (#) the line plt.rc('font', **{'sans-serif' : 'Arial', 'family' : 'sans-serif'})
  • both text ("A distance (μm) (or $\mu$m)") and u("A distance (μm) (or $\mu$m)") do the same error.

C:\Users\parent\Desktop\winpython\WinPython-32bit-3.3.2.3\python-3.3.2\lib\site-packages\matplotlib\mathtext.py:876: MathTextWarning: Font 'default' does not have a glyph for 'b'\u03bc'' [U3bc]
MathTextWarning)
C:\Users\parent\Desktop\winpython\WinPython-32bit-3.3.2.3\python-3.3.2\lib\site-packages\matplotlib\mathtext.py:877: MathTextWarning: Substituting with a dummy symbol.
warn("Substituting with a dummy symbol.", MathTextWarning)

(\u03bc is "µ" in utf16, apparently http://www.fileformat.info/info/unicode/char/3bc/index.htm)

@mdboom
Copy link
Member

mdboom commented Sep 10, 2013

Most likely, that error message is correct: your font (which you've set to Arial) does not have that character. You can confirm this by opening the font in a tool that will show its glyph set (such as fontforge). Try another font with better unicode coverage.

@stonebig
Copy link
Contributor Author

My real question is , what/which tool select this default font , is it Matplotlib default ?
(for newbies, it is better when it works correctly out-of-the box, so I want to put the default-change request on the pertinent tool, unless as matplotlib detects the issue, it can switch "on the fly" when the issue arise ?)

@mdboom
Copy link
Member

mdboom commented Sep 10, 2013

No, the default is Bitstream Vera Sans, which has this character. You have changed it here:

plt.rc('font', **{'sans-serif' : 'Arial', 'family' : 'sans-serif'})

@stonebig
Copy link
Contributor Author

So, If I understand well, this is the tool calling matplotlib that changes the default to a non-pertinent value ?
Ok, it seems the problem is in spyder default settings on my system.
Thank you very much, I wouldn't have find out alone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants