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

"\usepackage[russian]{babel}" does not work in matplotlib 1.3.1 #2636

Merged
merged 1 commit into from Dec 6, 2013

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Dec 5, 2013

Example:

from matplotlib import rc
#rc('font', **{'family': 'serif'})
rc('text', usetex=True)
rc('text.latex', unicode=True)
rc('text.latex', preamble=r"\usepackage[utf8]{inputenc}")
rc('text.latex', preamble=r"\usepackage[russian]{babel}")

import matplotlib.pyplot as plt

plt.figure(1)

plt.plot([1, 2, 3, 4], [1, 2, 3, 4], '-')
plt.xlabel(u"ось абсцисс")
plt.ylabel(u"ось ординат")
plt.title(u"Заголовок")
plt.show()

The error message:

Traceback (most recent call last):
  File "/usr/lib64/python3.3/tkinter/__init__.py", line 1475, in __call__
    return self.func(*args)
  File "/usr/lib64/python3.3/site-packages/matplotlib/backends/backend_tkagg.py", line 276, in resize
    self.show()
  File "/usr/lib64/python3.3/site-packages/matplotlib/backends/backend_tkagg.py", line 348, in draw
    FigureCanvasAgg.draw(self)
  File "/usr/lib64/python3.3/site-packages/matplotlib/backends/backend_agg.py", line 451, in draw
    self.figure.draw(self.renderer)
  File "/usr/lib64/python3.3/site-packages/matplotlib/artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib64/python3.3/site-packages/matplotlib/figure.py", line 1035, in draw
    func(*args)
  File "/usr/lib64/python3.3/site-packages/matplotlib/artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib64/python3.3/site-packages/matplotlib/axes.py", line 2088, in draw
    a.draw(renderer)
  File "/usr/lib64/python3.3/site-packages/matplotlib/artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib64/python3.3/site-packages/matplotlib/axis.py", line 1094, in draw
    renderer)
  File "/usr/lib64/python3.3/site-packages/matplotlib/axis.py", line 1043, in _get_tick_bboxes
    extent = tick.label1.get_window_extent(renderer)
  File "/usr/lib64/python3.3/site-packages/matplotlib/text.py", line 755, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "/usr/lib64/python3.3/site-packages/matplotlib/text.py", line 321, in _get_layout
    ismath=False)
  File "/usr/lib64/python3.3/site-packages/matplotlib/backends/backend_agg.py", line 205, in get_text_width_height_descent
    renderer=self)
  File "/usr/lib64/python3.3/site-packages/matplotlib/texmanager.py", line 669, in get_text_width_height_descent
    page = next(iter(dvi))
  File "/usr/lib64/python3.3/site-packages/matplotlib/dviread.py", line 85, in __iter__
    have_page = self._read()
  File "/usr/lib64/python3.3/site-packages/matplotlib/dviread.py", line 146, in _read
    self._dispatch(byte)
  File "/usr/lib64/python3.3/site-packages/matplotlib/dviread.py", line 234, in _dispatch
    self._fnt_def(k, c, s, d, a, l, n)
  File "/usr/lib64/python3.3/site-packages/matplotlib/dviread.py", line 395, in _fnt_def
    if c != 0 and tfm.checksum != 0 and c != tfm.checksum:
AttributeError: 'NoneType' object has no attribute 'checksum'

@mdboom
Copy link
Member

mdboom commented Dec 2, 2013

I can't reproduce this with matplotlib 1.3.1 on Python 2.7 or 3.3. What platform are you on? It's most likely that the tfm files for the Russian fonts are not on your system or in a non-standard place. On Fedora, I installed the textlive-collection-cyrillic package and has no issues.

@Avernial
Copy link
Author

Avernial commented Dec 4, 2013

Tested on platforms OpenSUSE 11.3, 13.1. textlive-collection-cyrillic installed.

@mdboom
Copy link
Member

mdboom commented Dec 4, 2013

I'm at a bit of a loss, then. Have you tried deleting the font cache? (~/.cache/matplotlib/fontList.py3k.cache)

@Avernial
Copy link
Author

Avernial commented Dec 5, 2013

Unfortunately, it does not help.

Error occurs when the function _tfmfile is called with the parameter b'lass1200'. The function returns None. Where it should be located?

@Avernial
Copy link
Author

Avernial commented Dec 5, 2013

Thank you for your help. Error was in the package texlive.

The workaround is to create the directory /home/user/.cache/texmf and then execute texhash texmf/.
And in the file / etc/texmf/web2c replace TEXMFHOME = $HOME/texmf to TEXMFHOME = $HOME/.cache/texmf/.

@Avernial
Copy link
Author

Avernial commented Dec 5, 2013

There was another problem. Extra characters юя and ``` in pdf.
test

@mdboom
Copy link
Member

mdboom commented Dec 5, 2013

Good find. That occurs only on Python 3.

I've attached a fix here. @Avernial: are you able to test it?

@Avernial
Copy link
Author

Avernial commented Dec 5, 2013

The fix https://github.com/mdboom/matplotlib/commit/38d846baed9080b67f9fdf96a0f163d230ba9ffb works fine. Thank you.

test

mdboom added a commit that referenced this pull request Dec 6, 2013
"\usepackage[russian]{babel}" does not work in matplotlib 1.3.1
@mdboom mdboom merged commit 45ee98c into matplotlib:v1.3.x Dec 6, 2013
@mdboom mdboom deleted the font/unicode-python3-pdf branch August 7, 2014 13:53
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

Successfully merging this pull request may close these issues.

None yet

2 participants