-
-
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
Changes from all commits
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 |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
from matplotlib.colors import BoundaryNorm, LogNorm | ||
from matplotlib.cm import get_cmap | ||
from matplotlib.colorbar import ColorbarBase | ||
from matplotlib import ticker, cm | ||
from matplotlib.mlab import bivariate_normal | ||
|
||
|
||
def _get_cmap_norms(): | ||
|
@@ -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 commentThe 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_max', | ||
'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 commentThe reason will be displayed to describe this comment to others. Learn more. Not used. |
||
N = 100 | ||
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 commentThe 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. |
||
+ 0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)) | ||
plt.figure() | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. For condensing the example you can use 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. Thanks. Will fix this test up. |
||
|
||
plt.figure() | ||
plt.subplot(111) | ||
plt.contourf(X, Y, z, cmap=cm.PuBu_r, locator=ticker.LogLocator(), | ||
extend='max') | ||
plt.colorbar() | ||
|
||
plt.figure() | ||
plt.subplot(111) | ||
plt.contourf(X, Y, z, cmap=cm.PuBu_r, locator=ticker.LogLocator(), | ||
extend='both') | ||
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.
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.