-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Fix formatter reset when twin{x,y}() is called #1145
Conversation
Damon - awesome! I thought this was going to be a mammoth job to fix this problem, so its awesome that it turned out to be such a simple change. I wonder if it would be better to add a kwarg to set_scale which disables the default scale setting instead? This would have the benefit of preserving the 2 formatters, and the 2 locators, and mean that you don't have to save the original and then re-apply it post calling |
Thanks Phil. Like I said, I've got some free time. Though this took a quite a bit of digging to track down! So, I was wondering almost the same thing. After I made this PR I thought perhaps the problem is not Perhaps it's actually better to separate the scale, formatter and locaters more. Keep them more modular. Currently Thoughts? |
I'm inclined to agree. However, that would make a significant change which could subtly change existing code's behaviour. Given that we have now missed the 1.2.x feature freeze deadline, the only "proper" way of getting this useful fix into 1.2 is if the change is more of a minor bug-fix (such as the one you have proposed, or by adding a simple keyword to trigger the behaviour). My preference would be the latter, but either way is better than not at all. Does anyone else have a preference? |
I wanted to add one more thing. After a little more thought, I think adding a |
I think the fact that But as for this quick fix for an obvious bug, I think this does the trick. |
OK. My preference remains with a toggle keyword, but I agree that this approach "does the trick", so lets run with it. Presumably there isn't a test for this, which we may wish to add. Additionally, we will want to document the bug fix. (there are 3 places to put change logs, and I am never entirely confident where to put things). |
If it is a new feature, whats_new.rst Admittedly, there are times when changes seem to fall into both categories |
I think this particular one should probably go in |
On 2012/08/29 3:54 AM, Michael Droettboom wrote:
Agreed. It is a fix for a somewhat obscure bug, not a substantially new |
Explicitly document the slight change in behaviour of Axes.twin[xy]
@@ -852,7 +852,15 @@ def cla(self): | |||
self.xaxis.minor = self._sharex.xaxis.minor | |||
x0, x1 = self._sharex.get_xlim() | |||
self.set_xlim(x0, x1, emit=False, auto=None) | |||
|
|||
# Save the current formatter so we don't lose it | |||
frmt = self._sharex.xaxis.get_major_formatter() |
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 doesn't actually preserve the locators nor the minor formatters, unless I am mistaken. It was for this reason that I proposed the kwarg addition, to avoid you having to copy and paste the four line prefix and suffix to set_scale
. Given that we seem to have agreed to not implementing the keyword, I still think you will need to handle the minor formatter, and both locators.
This will need a simple test before merging. Something that exercises both locators and formatters using both the major and minor positions. |
@@ -62,6 +62,29 @@ def test_formatter_large_small(): | |||
y = [500000001, 500000002] | |||
ax.plot(x, y) | |||
|
|||
@image_comparison(baseline_images=["twin_axis_locaters_formatters"]) |
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.
We probably only need to test this with one format. Perhaps png is best performance wise.
Thanks Damon. All looks good to me. The only comment might be to reduce the number of file formats being tested. TBH, in this case it might not have even been necessary to produce a visual test, but I don't propose that you change that now. Thanks for this. |
This addresses #1110. In particular.
The functions
Axes.twiny
andAxes.twinx
create a new set ofAxes
objects. TheAxes.cla
method is called during the constructor to do some setup. If a shared axes is passed in, a copy of thescale
is executed, which overwrites the current formatter. To fix it, I've stored in a temporary variable before thescale
copy, then restore it to use the original formatter.