Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[ENH]: ticker.EngFormatter: allow offset #28463

Open
Milestone
@doronbehar

Description

@doronbehar

Problem

I want to be able to generate this plot:

Screenshot from 2024-06-26 01-11-31

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp