FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Clipped tick labels · Issue #8609 · matplotlib/matplotlib · GitHub

Repository navigation

Clipped tick labels #8609

Closed
Closed

Description

Bug report

Bug summary
Clipped tick labels if emojis were used

Code for reproduction

from __future__ import unicode_literals

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
tick_labels = ['😃', '😎', '😴', '😲', '❤️']
y = [1, 4, 9, 16, 25]
x = range(5)
ax.bar(x, y, tick_label=tick_labels, align='center')
ax.xaxis.set_tick_params(labelsize=20)

ax.set_title('Диаграмма со смайликами')

Actual outcome

Expected outcome
The tick labels are not clipped

Matplotlib version

  • Operating System: Windows 10 1610
  • Matplotlib Version: 2.0.2
  • Python Version: 3.6.1
  • Jupyter Version (if applicable):
  • Other Libraries:

Activity

  1. added this to the milestone on May 14, 2017
  2. tacaswell commented on May 14, 2017

    Member

    http://matplotlib.org/users/dflt_style_changes.html#fonts renders correctly (which was rendered on the computer I am using right now) as does http://matplotlib.org/devdocs/users/dflt_style_changes.html#fonts which renders on travis (both linux).

    How did you install Matplotlib and which version of freetype are you using?

    Does it work if you make the font size smaller? Do you have anything about fonts in your rcparams?

    My knee-jerk guess is that something is wrong with the font-metrics and we are copy too-small of a buffer. No good guess why this is happening on windows and not linux.

  3. a113n commented on May 15, 2017

    Author

    Thanks for looking into the issue!

    I think if you change one of the symbols in http://matplotlib.org/users/dflt_style_changes.html#fonts to smaller symbols such as '❤️' or any alphanumeric characters, the larger ones would be clipped as well.

    This behavior can be observed on both Ubuntu 16.04 and Windows 10. My rcparams are not modified.

  4. modified the milestones: , on Aug 14, 2017
  5. modified the milestones: , on Oct 9, 2017
  6. drammock commented on Jan 24, 2018

    FWIW, I get a similar error when I use IPA glyphs in axis labels (ʃ, ʒ, ð etc), but it only happens in interactive plotting (Qt5Agg) and when generating PNGs, but not when saving to PDF, EPS, or SVG.
    (mpl 2.0.2, python 3.6.1, linux)

  7. anntzer commented on Jan 25, 2018

    Contributor

    I can repro too (default rcparams, 2.1.2 or master, archlinux).
    #9763 fixes the issue, so it's not clearly (not "clearly not" :-)) a font metrics thing...

  8. vincentzlt commented on May 7, 2019

    still got similar problem with chinese characters in 3.0.3

  9. vincentzlt commented on Jul 6, 2019

    still got similar problem with chinese characters in 3.1.1

  10. anntzer commented on Jul 6, 2019

    Contributor

    #8609 (comment) was the important hint: looks like

    diff --git i/lib/matplotlib/backends/backend_agg.py w/lib/matplotlib/backends/backend_agg.py
    index c5545ae80..30689f403 100644
    --- i/lib/matplotlib/backends/backend_agg.py
    +++ w/lib/matplotlib/backends/backend_agg.py
    @@ -178,12 +178,9 @@ class RendererAgg(RendererBase):
     
             if font is None:
                 return None
    -        if len(s) == 1 and ord(s) > 127:
    -            font.load_char(ord(s), flags=flags)
    -        else:
    -            # We pass '0' for angle here, since it will be rotated (in raster
    -            # space) in the following call to draw_text_image).
    -            font.set_text(s, 0, flags=flags)
    +        # We pass '0' for angle here, since it will be rotated (in raster
    +        # space) in the following call to draw_text_image).
    +        font.set_text(s, 0, flags=flags)
             font.draw_glyphs_to_bitmap(antialiased=rcParams['text.antialiased'])
             d = font.get_descent() / 64.0
             # The descent needs to be adjusted for the angle.

    fixes the issue. Indeed, the problem is that load_char does not resize the font's internal buffer, which gets sizes by the smaller "heart" character (which is measured while we prepare for aligning the labels -- we measure all labels before rendering all of them).

    The special handling of single-non-ASCII characters was added a long time ago in 29371f9; tbh it's not clear to me why it's necessary (for example it isn't used for longer non-ascii strings...).

    Now it would be nice to have a way to test this without a baseline image...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL