Description
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
.