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

BUG: clabel manual mode doesn't make a gap big enough in contour · Issue #8819 · matplotlib/matplotlib · GitHub

Repository navigation

BUG: clabel manual mode doesn't make a gap big enough in contour #8819

Closed

Description

Bug report

Bug summary

Using plt.clabel(manual=True) adds labels but the labels are not easily readable because only a small gap is created in the contour.

Code for reproduction

The following works:

plt.figure()
x = np.arange(400).reshape((20,20))
c = plt.contour(x)
plt.clabel(c)

But the following doesn't give as nice a result:

plt.figure()
x = np.arange(400).reshape((20,20))
c = plt.contour(x)
plt.clabel(c, manual=True)
# click around

This happens with both the Qt5 and MacOS X backends, and I am using a retina display.

Matplotlib version

  • Operating System: MacOS X 10.11
  • Matplotlib Version: 2.0.2
  • Python Version: 3.6.1

Activity

  1. tacaswell commented on Jun 29, 2017

    Member

    My guess is that this is a dpi scaling related issue as there is a mapping from screen-space back to data space...

  2. added this to the milestone on Jun 29, 2017
  3. modified the milestones: , on Sep 24, 2017
  4. modified the milestones: , on Oct 9, 2017
  5. anntzer commented on Jan 13, 2019

    Contributor

    FWIW I can't repro on a non-high-DPI display, even using QT_SCALE_FACTOR to fake one.

  6. anntzer commented on Jan 13, 2019

    Contributor

    But perhaps @astrofrog you can try whether something along the lines of

    diff --git i/lib/matplotlib/contour.py w/lib/matplotlib/contour.py
    index 59b9fe63b..198aa78f9 100644
    --- i/lib/matplotlib/contour.py
    +++ w/lib/matplotlib/contour.py
    @@ -17,9 +17,7 @@ import matplotlib.collections as mcoll
     import matplotlib.font_manager as font_manager
     import matplotlib.text as text
     import matplotlib.cbook as cbook
    -import matplotlib.mathtext as mathtext
     import matplotlib.patches as mpatches
    -import matplotlib.texmanager as texmanager
     import matplotlib.transforms as mtransforms
     
     # Import needed for adding manual selection capability to clabel
    @@ -263,24 +261,12 @@ class ContourLabeler(object):
             """
             if not isinstance(lev, str):
                 lev = self.get_text(lev, fmt)
    -
    -        lev, ismath = text.Text.is_math_text(lev)
    -        if ismath == 'TeX':
    -            if not hasattr(self, '_TeX_manager'):
    -                self._TeX_manager = texmanager.TexManager()
    -            lw, _, _ = self._TeX_manager.get_text_width_height_descent(lev,
    -                                                                       fsize)
    -        elif ismath:
    -            if not hasattr(self, '_mathtext_parser'):
    -                self._mathtext_parser = mathtext.MathTextParser('bitmap')
    -            img, _ = self._mathtext_parser.parse(lev, dpi=72,
    -                                                 prop=self.labelFontProps)
    -            lw = img.get_width()  # at dpi=72, the units are PostScript points
    -        else:
    -            # width is much less than "font size"
    -            lw = (len(lev)) * fsize * 0.6
    -
    -        return lw
    +        fig = self.ax.figure
    +        width = (text.Text(0, 0, lev,
    +                           figure=fig, fontproperties=self.labelFontProps)
    +                 .get_window_extent(fig.canvas.get_renderer()).width)
    +        width *= 72 / fig.dpi
    +        return width
     
         def set_label_props(self, label, text, color):
             """Set the label properties - color, fontsize, text."""
    

    helps?
    Note that get_window_extent() also takes dpi as a second argument; you may also want to check whether setting the value there helps...

  7. anntzer commented on Oct 18, 2019

    Contributor

    Can anyone with a high-dpi display check this?

  8. jklymak commented on Oct 18, 2019

    Member

    Check what? The patch or just that the original issue is there?

  9. anntzer commented on Oct 18, 2019

    Contributor

    Both.

  10. jklymak commented on Oct 18, 2019

    Member

    The clabel works fine on master w/ hi-dpi and Qt5Agg. Didn't check the patch (do I need to?)

  11. jklymak commented on Oct 18, 2019

    Member

    Note I don't manually set the dpi at any point.

  12. anntzer commented on Oct 18, 2019

    Contributor

    Let's ping @astrofrog to see whether he can give this a try again; if there's no reply we'll just close this.

  13. timhoffm commented on Nov 5, 2019

    Member

    Assuming fixed on master. Please ping if the problem still exists.

  14. removed this from the future releases milestone on Oct 6, 2022
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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL