Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Open
Labels
Milestone
Description
Problem
I want to be able to generate this plot:
I managed to create this plot using the following code:
fromitertoolsimportcountfrommathimportcopysign# https://pypi.org/project/prefixed/fromprefixedimportFloatfrommatplotlib.tickerimportScalarFormatterclassFrequencyFormatter(ScalarFormatter):defformat_data(self,value):# Add the Hz suffixreturn'{:H}Hz'.format(Float(value))def_set_order_of_magnitude(self):super()._set_order_of_magnitude()c=abs(self.orderOfMagnitude)# Search 0, -3, 3, -6, 6, -9, 9 etc until the best scientifically# prefixed oom is found, and then set self.orderOfMagnitude to itforsciOomincount(3,3):ifc<sciOom:self.orderOfMagnitude=copysign(sciOom,self.orderOfMagnitude)break# fig,ax...ax.yaxis.set_major_formatter(FrequencyFormatter(# I'm not necessarily interested in this, but without this,# ScalarFormatter.get_offset doesn't use my own .format_data function to# format also the offset.useMathText=True))
It is not ideal because it relies both upon modifying (the private)_set_order_of_magnitude method and the external libraryprefixed, which implements something already implemented in theEngFormatter.
I'm surprised thatEngFormatter doesn't handle offsets so smartly likeScalarFormatter...
Where do you think this kind of enhancement would fit most? InEngFormatter with an additional__init__ argument? Or in a new formatter?
Proposed solution
Sort of proposed above...
