Skip to content

No space before unit symbol when there is no SI prefix in ticker.EngFormatter #6009

Closed

Description

@afvincent

I just discovered the EngFormatter in matplotlib.ticker, something I was looking for since a long time :). Playing a bit with it, it seems to me that a space is missing before the unit symbol when no SI prefix is needed. For example 1e3 seconds is rendered correctly by “1 ks” but 10 seconds is displayed “10s” (which is wrong afaik about English typography).

I looked rapidly into the EngFormatter class, and I think the problem can be solved by tweaking the format_eng method, for example like in the following patch:

'''
NB: At the end, the ticklabel will basically be the string s = "%s%s" % (self.format_eng(x), self.unit)
So the idea is just to enforce an additional space at the end of what format_eng returns when there is no SI prefix but a unit is specified.
'''

Vanilla return

return formatted.strip()

Patched return

stripped_formatted = formatted.strip()
if (self.unit is not "") and (prefix is self.ENG_PREFIXES[0]):
stripped_formatted = stripped_formatted + " "
return stripped_formatted

Maybe there is a better way to achieve this though. (BTW, I'm sorry but I didn't achieve to get indentation working for the “if” statement). To demonstrate the problem and the proposed solution, I attach a ZIP with a script that plots the same axes with both the vanilla EngFormatter and my patched version, and the produced figure as a PDF: Proposition_of_patch_for_EngFormatter.zip
.

Activity

  1. tacaswell commented on Feb 17, 2016

    @tacaswell
    Member

    Seems reasonable, Could you open a pull request with that change?

  2. added this to the milestone on Feb 17, 2016
  3. added a commit that references this issue on Jun 6, 2016
    59e0ab9
  4. modified the milestones: , on Jun 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions