-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Ability to scale axis by a fixed factor #10321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
df16efc
45e1bf3
d001033
b12202a
130f257
482e07a
38af9db
c23ef3b
d2a1769
01fb668
3260e70
2188177
50a9695
5465a81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Ability to scale axis by a fixed order of magnitude | ||
--------------------------------------------------- | ||
|
||
To scale an axis by a fixed order of magnitude, set the *scilimits* argument | ||
of ``Axes.ticklabel_format`` to the same lower and upper limits. Say to scale | ||
the y axis by a million (1e6), use ``ax.ticklabel_format(style='sci', scilimits=(6, 6), axis='y')`` | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,6 +228,17 @@ class TestScalarFormatter(object): | |
|
||
use_offset_data = [True, False] | ||
|
||
scilimits_data = [ | ||
(False, (0, 0), (10.0, 20.0), 0), | ||
(True, (-2, 2), (-10, 20), 0), | ||
(True, (-2, 2), (-20, 10), 0), | ||
(True, (-2, 2), (-110, 120), 2), | ||
(True, (-2, 2), (-120, 110), 2), | ||
(True, (-2, 2), (-.001, 0.002), -3), | ||
(True, (0, 0), (-1e5, 1e5), 5), | ||
(True, (6, 6), (-1e5, 1e5), 6), | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a scalar example into here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we've decided not to take in scalar anymore, this is a moot point..., but just for posterity sake, my intention was to allow scalar input at the ticklabel_format API level, not at this lower level, where the test sits. The scalar input would then be translated to pair of (repeated) values for lower level consumption. |
||
|
||
@pytest.mark.parametrize('left, right, offset', offset_data) | ||
def test_offset_value(self, left, right, offset): | ||
fig, ax = plt.subplots() | ||
|
@@ -257,6 +268,18 @@ def test_use_offset(self, use_offset): | |
tmp_form = mticker.ScalarFormatter() | ||
assert use_offset == tmp_form.get_useOffset() | ||
|
||
@pytest.mark.parametrize( | ||
'sci_type, scilimits, lim, orderOfMag', scilimits_data) | ||
def test_scilimits(self, sci_type, scilimits, lim, orderOfMag): | ||
tmp_form = mticker.ScalarFormatter() | ||
tmp_form.set_scientific(sci_type) | ||
tmp_form.set_powerlimits(scilimits) | ||
fig, ax = plt.subplots() | ||
ax.yaxis.set_major_formatter(tmp_form) | ||
ax.set_ylim(*lim) | ||
tmp_form.set_locs(ax.yaxis.get_majorticklocs()) | ||
assert orderOfMag == tmp_form.orderOfMagnitude | ||
|
||
|
||
class FakeAxis(object): | ||
"""Allow Formatter to be called without having a "full" plot set up.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little mysterious to the un-initiated. i.e. why the heck do I have to specify 6 twice in this argument. I'd say something before that about the "old" way that this worked, and how this is a special case.
I think I agree w/ @tacaswell that this might as well also allow a single integer. Having a plural in the kwarg name isn't really a good reason to not allow this; limits collapse to single values all the time.