Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: Check for colorbar creation with multi-dimensional alpha #20788

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

Merged
merged 1 commit into from
Aug 6, 2021

Conversation

greglucas
Copy link
Contributor

PR Summary

Raise a ValueError if a colorbar is created with a collection that has an alpha that is an array. This also adds the ability to override the collection's alpha with a scalar.

closes #19843
closes #20785

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@jklymak
Copy link
Member

jklymak commented Aug 4, 2021

I am not sure about this. I'd just set alpha to one if it's an ndarray. I think we also need to do the same thing in set_alpha.

@greglucas
Copy link
Contributor Author

I'm not sure we should do that silently though? I could change to a warning here instead, but raising an error makes it explicit that a user needs to specify what they want the colorbar to display.

@jklymak
Copy link
Member

jklymak commented Aug 4, 2021

I guess I think 99% of the time they want the colours to display without alpha. I guess you could get someone who set all the alphas the same but still specified an array, but that's the only case I can think of where you would want a non-one alpha applied. But we can let others pipe up as well..

@greglucas
Copy link
Contributor Author

I don't have a real strong preference here. I agree that is probably what most people want and a warning may be too much even. This will fix the error out case and if someone wants more control/options that can be implemented later.

@@ -582,8 +582,10 @@ def _add_solids(self, X, Y, C):
and any(hatch is not None for hatch in mappable.hatches)):
self._add_solids_patches(X, Y, C, mappable)
else:
# Ignore alpha if the user provided an explicit array
alpha = None if isinstance(self.alpha, np.ndarray) else self.alpha
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think self.alpha on the colorbar should be the alpha being used by the colorbar - so we could set the alpha properly in the init and in update_normal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I updated set_alpha to handle both cases in the same place. It still seems unfortunate to get the colorbar's alpha out of sync with the mappable's alpha. But, I think that will only happen in this case.

Looks like there is #7430 with more discussion around a similar topic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean if you are planning to push through syncing them, we could do something else, like store a pointer to the mappable and just check it at draw time - I don't see any reason for the user to have the ability to set the alpha of the colorbar manually so that it is out of sync with the mappable, but maybe some folks want partially transparent colorbars? But if so that would have to apply to the axes, ticks etc as well....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why the colorbar has a set_alpha(), I assume this may have been for when the colorbar+alpha looked blocky and allowed someone to force fully opaque just so it looks nicer. I could look into deprecating/modifying that in a separate issue/PR. I think something basic like this should get in for the releases as the current error is not descriptive of what the problem actually is.

If an array-like alpha is provided, we set the colorbar alpha to None
to use the colormap's transparency values. This would previously error.
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good. Not sure what happens if someone specifies a singleton ndarray, but thats enough of a corner case we could deal with it if it comes up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Colorbar creation from pcolormesh with cell specific alpha values collection with alpha + colorer
3 participants