-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement extend color bar for contourf #8806
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
Conversation
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.
Thank you for filling in this gap in colorbar.
if self.logscale: | ||
tempLocator = LogLocator() | ||
if self.locator is not None: | ||
tempLocator = self.locator |
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.
Instead of using a temporary Locator and then requiring that all Locators have 3 new private methods, I think it would be better to keep everything within the ContourBase class. This will be more readable than using Locator private methods that modify one of their arguments. It will likely require fewer LOC as well.
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.
@efiring Thank you for the input. I took sometimes to think it over more carefully, I will fix it your way.
@@ -308,3 +310,34 @@ def test_colorbar_lognorm_extension(): | |||
cb = ColorbarBase(ax, norm=LogNorm(vmin=0.1, vmax=1000.0), | |||
orientation='vertical', extend='both') | |||
assert cb._values[0] >= 0.0 | |||
|
|||
|
|||
@image_comparison(baseline_images=['extended_cbar_with_contourf_min', |
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.
Please condense the test down to a single image with 3 subplots, saving time and space.
'extended_cbar_with_contourf_both'], | ||
extensions=['png']) | ||
def test_extended_colorbar_on_contourf(): | ||
np.random.seed(1) |
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.
Not used.
x = np.linspace(-3.0, 3.0, N) | ||
y = np.linspace(-2.0, 2.0, N) | ||
X, Y = np.meshgrid(x, y) | ||
z = (bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0) |
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.
For the purpose of a test you can use a simpler pattern with far fewer points. For example, you could use
z = np.logspace(0.1, 10, 24).reshape((4, 6))
and omit the X and Y entirely.
plt.subplot(111) | ||
plt.contourf(X, Y, z, cmap=cm.PuBu_r, locator=ticker.LogLocator(), | ||
extend='min') | ||
plt.colorbar() |
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.
For condensing the example you can use fig, axs = plt.subplots(ncols=3)
and then use Axes and Figure method calls.
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.
Thanks. Will fix this test up.
Here is what I came up with:
|
Yes. That can work. But shouldn't self._levels be scaled with whatever base of LogNorm? I.e lamda x: x*some_base ? LogNorm takes more than 1 bases and self._levels is used in calculating rgba. I mean when firing up debugger, I see values of |
No, just as the value added or subtracted in the linear case (1) is arbitrary, so long as it is positive, the multiplier or divisor in the log case is also arbitrary, so long as it is greater than 1. It merely needs to push the level outside the normed range so that the "under" and "over" colors of the colormap are used. |
Ah. I see. Thanks for clarifying that. I think your implementation is better. Please commit it. |
@Tuan333 did you mean to close this and delete your branch? |
I haven't made an alternative PR yet, but I have committed the implementation suggested above. I find that specifying a LogLocator really doesn't do anything sensible at present, regardless of the extend kwarg. I think I have a fix for that, and to be consistent it will also make an improvement in the case with no locator specified and with the extend kwarg. I think this is a rare use case, so I'm not too worried about the behavior change. |
@efiring @tacaswell oops... I thought this is not needed anymore and moved on to some other bugs I'm interested in. Should I have left this open? (genuine mistake/question) |
I think closing it is fine. If you don't see a PR from me on this within a week, ping me. |
PR Summary
Implement extend keyword for lognorm color bar on contourf. Travis ci might sometimes timeout during installation (before testing starts) and fails.
PR Checklist