8000 Unicode invisible after image saved · Issue #6326 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
8000

Unicode invisible after image saved #6326

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

Closed
sumomoshinqi opened this issue Apr 23, 2016 · 10 comments
Closed

Unicode invisible after image saved #6326

sumomoshinqi opened this issue Apr 23, 2016 · 10 comments

Comments

@sumomoshinqi
Copy link

OSX 10.11.4, Python 2.7.10, Matplotlib 1.3.1
Unicode characters were displayed correctly in the figure. But after saving, they went disappeared.
2016-04-23 11 18 12
figure_1
I was making a nltk like dispersion plot for Unicode text.

def dispersion_plot(text, words, title="Lexical Dispersion Plot"):
    points = [(x,y) for x in range(len(text))
                    for y in range(len(words))
                    if text[x].encode('utf8') == words[y].encode('utf8')]
    if points:
        x, y = list(zip(*points))
    else:
        x = y = ()
    pylab.plot(x, y, "b|", scalex=.1)
    pylab.yticks(list(range(len(words))), words, color="b")
    pylab.ylim(-1, len(words))
    pylab.title(title)
    pylab.xlabel("Word Offset")
    pylab.show()
@jenshnielsen
Copy link
Member

By the looks of your image. I think the issue is that the symbols that you are using are simply missing in the font used to save the figure. Empty boxes are the general missing symbol fallback. Given that you are on OSX you are probably using the Mac OSX backend to display the figure but the image is saved with the Agg backend. Unfortunatly the OSX backend uses a different font loading system so it likely picks a different font.

I would suggest trying to select a different font and see if that changes anything

@sumomoshinqi
Copy link
Author

The problem still exists. In the matplotlabrc it's said I'm using MacOSX backend. And default font family is sans-serif including helvetica. I tried to put helvetica 8000 as first choice but it didn't work. And I couldn't find other font options in the SAVING FIGURES section. How should I change default font when saving the figures? Adding parameters like rcParams['font.family'] = 'Menlo' only affects what's showing in the Python window.

@gepcel
Copy link
Contributor
gepcel commented Apr 24, 2016

I've met some problems like this long time ago. Don't remember how I managed to get this work. But I think there's an issue similar to this, see #4492.
You can try something like, and see what comes

pylab.yticks(list(range(len(words))), words, color="b", fontname='SimHei')

About font, there are a few ways to set it:

  1. In the file matplotlibrc there is a font.family
  2. rcParams['font.family'] = ...
  3. text(..., fontname=..) or text(.., fontproperties=..)

I think one of those might work.

@sumomoshinqi
Copy link
Author

Hi @gepcel! It worked by adding fontname=.... And it seems to be about setting the font name, not family, as suggested in #4492.

@gepcel
Copy link
Contributor
gepcel commented Apr 24, 2016

Glad, it helped. Problem solved, but issue exists. Figure saving and showing are using different fonts. Right?

@sumomoshinqi
Copy link
Author

By default, yes. Adding fontname='SimHei' changed both. But if I only set the font.family parameter, OS X's backend and Agg backend will choose different font therefore figure saving and showing will be different, like what @jenshnielsen said above.

@sumomoshinqi sumomoshinqi reopened this Apr 25, 2016
@efiring
Copy link
Member
efiring commented Apr 25, 2016

mpl version 1.3.1 is pretty old, and prior to the soon-to-be-released 2.0 the OS X backend had quite a few peculiarities. The new version is using Agg for rendering. Can you build and test the version in master or the 2.0 branch? Or try a 1.5.1 release? I would not be surprised if font selection was changed between 1.3.1 and 1.5.1.

@sumomoshinqi
Copy link
Author

Hi, problem still exists with 1.5.1 :-)

@jenshnielsen
Copy link
Member

The issue of OSX vs Agg chosing differently will be fixed in the next release. Is there any other remaining issue or can this close

@sumomoshinqi
Copy link
Author

Let's close this issue. Thanks.

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

4 participants
0