Skip to content

[Bug]: cm fontset in log scale does not use Unicode minus #21540

Closed

Description

@Atcold

Bug summary

Minuses are shown as dashes when choosing the log scale, both in the exponent and in front of the actual number.

Code for reproduction

plot([-10, 10], [-10, 10])
yscale('symlog', linthresh=.1)

Actual outcome

image

Expected outcome

Minuses should be shown as minuses and not dashes.

Operating system

OS/X

Matplotlib Version

3.4.3

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.8.1

Jupyter version

3.2.1

Other libraries

No response

Installation

conda

Conda channel

No response

Activity

  1. QuLogic commented on Nov 4, 2021

    @QuLogic
    Member

    This looks fine to me:
    image
    Maybe it's your theme?

  2. dstansby commented on Nov 6, 2021

    @dstansby
    Member

    Yes, works fine for me on v3.4.3 and the following code:

    from matplotlib.pyplot import *
    
    plot([-10, 10], [-10, 10])
    yscale('symlog', linthresh=.1)
    show()
    ``
    
    I'm going to close as not an issue as two of us have checked - @Atcold feel free to comment/re-open if you think we've missed something.
  3. Atcold commented on Nov 19, 2021

    @Atcold
    Author

    Adding style.use(['bmh']) will show the bug.
    So the theme is breaking it.
    Not sure how to reopen this issue.

    @QuLogic that didn't really look too fine to me, haha.
    image

  4. QuLogic commented on Nov 20, 2021

    @QuLogic
    Member

    Ah, bmh sets the cm fontset, and that doesn't appear to support the minus sign properly. Also, it doesn't seem like the Log formatters do any minus sign glyph substitution, but I may have missed it.

    You can replicate this more easily by setting mpl.rcParams['mathtext.fontset'] = 'cm', and if you don't mind going back to DejaVu Sans, can work around it by setting mpl.rcParams['mathtext.fontset'] = 'dejavusans' after setting the style.

  5. changed the title [-][Bug]: minuses are shown as dashes when choosing the log scale[/-] [+][Bug]: cm fontset in log scale does not use Unicode minus[/+] on Nov 20, 2021
  6. QuLogic commented on Nov 20, 2021

    @QuLogic
    Member

    A possible fix may be to do:

    diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py
    index 6d8fa5419b..c759403bbf 100644
    --- a/lib/matplotlib/ticker.py
    +++ b/lib/matplotlib/ticker.py
    @@ -1066,7 +1066,7 @@ class LogFormatterMathtext(LogFormatter):
             if x == 0:  # Symlog
                 return r'$\mathdefault{0}$'
     
    -        sign_string = '-' if x < 0 else ''
    +        sign_string = self.fix_minus('-') if x < 0 else ''
             x = abs(x)
             b = self._base

    though I'm not sure if this should be applied to LogFormatter as well (probably it should).

  7. anntzer commented on Nov 20, 2021

    @anntzer
    Contributor

    Agreed that we should use fix_minus in as many places as possible. (But see also #21687.)

  8. Atcold commented on Dec 3, 2021

    @Atcold
    Author

    Thanks for going to the bottom of this.

  9. added a commit that references this issue on Jan 7, 2022
    52003e4
  10. added this to the v3.6.0 milestone on Jan 11, 2022
  11. added a commit that references this issue on Jan 26, 2022
    df85ec0
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