-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MNT: more control of colorbar with CountourSet #5056
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
MNT: more control of colorbar with CountourSet #5056
Conversation
Why do you want to allow the user to generate a colorbar that is inconsistent with its mappable? I can see a reason for using setdefault for the extend kwarg (even though I think that overriding it is in general a bad idea, yielding a misleading plot), and I can see a reason for having a warning or error if a kwarg is being overridden, but I don't think that using setdefault to allow the user to destroy the linkage between the colorbar and the mappable, without even a warning, is a good idea. |
#5055 is a good example for things happening automatically in a "good way", i.e. informing the user "you did something wrong in your plot". About @efiring's comment, it seems to me that it is easy to generate a colorbar that is inconsistent with its mappable, essentially because of the "extend" keyword having to be set by the user. Neither the normalization nor the colorbar classes will warn the user who sets the norm's min/max bounds that the plotted data is actually out-of-bounds. This makes the clip=True keyword quite useless btw: the following code produces the same misleading plot with or without clipping. import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
x, y = np.mgrid[0:1:0.01, 0:1:0.01]
r = np.sqrt(x ** 2 + y ** 2)
z = np.sin(6 * np.pi * r)
cmap = mpl.cm.get_cmap('PuBuGn')
norm = mpl.colors.BoundaryNorm([0.1, 0.2, 0.3, 0.4], cmap.N)
plt.pcolormesh(x, y, z, norm=norm, cmap=cmap)
plt.colorbar() |
@tacaswell, looking at this again, I still object to silently breaking all of the linkages. It makes no sense whatsoever. For |
8c2049e
to
a9cad4a
Compare
@efiring I have re-jiggered how this works so it now raises a |
will now raise a `TypeError` rather than silently drop user supplied | ||
input. | ||
|
||
If ``mappable`` is a `contouer.ContourSet` then a `TypeError` will be raised |
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.
typo: "contouer"
b938f82
to
cc301b7
Compare
""" | ||
# deal with default value of alias_mapping | ||
if alias_mapping is None: | ||
alias_mapping = dict() |
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.
Just pointing out another way that I sometimes do it:
alias_mapping = alias_mapping or {}
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 a huge fan of that due to the many other things that are 'falsey' that will trigger the default behavior when (maybe?) they should not. ex, ''
should not work as the alias_mapping
Should I pick this PR apart so we can backport |
c7a69c0
to
6127cc6
Compare
In the `ColorBar` constructor values are extracted from the mappable if it is a ContourSet. Instead of always overwriting user-input only, respect user input if given. If the user passes in kwargs which can be extracted from a ContourSet raise TypeError instead of silently ignoring user input.
6127cc6
to
32aaee4
Compare
This seems useful (w/o spending too much time w/ it). If @tacaswell doesn't have time, maybe I'll take it over, or someone else can try and move it through... |
Superseded by #16051. |
In the
ColorBar
constructor values are extracted from the mappable ifit is a ContourSet. Instead of always overwriting user-input only,
respect user input if given.
This came up while looking into #5055
now results in
Currently on master the
extend
kwarg tocolorbar
was silently ignored.Possibly related to #5034 / #4850
attn @efiring @fmaussion @lkilcher