-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
ENH: Add option to define a color as color=(some_color, some_alpha) #24691
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.
I think this is not the right API to aim for, because it doesn't generalize at all, e.g. for markerfacecoloralt or for gapcolor). Perhaps supporting (colorstring, alpha) pairs could be a solution but in any case this needs more discussion.
Ack, sorry I didn't qualify my issue w/ a "please don't try to implement this yet!" b/c I threw my suggestion out there to seed discussion. (ETA: but also thanks for liking the idea enough to try and implement it!)
I was thinking of that, but to some extent that is the RGBA solution - maybe alpha can be obnoxiously explicit and also take a dict alpha={'facecolor': , edgecolor:' ', markerfacealt:} ? Granted, I think at that point then maybe it is the priority problem again - if the color is RGBA does it take precedence or alpha? Which granted is also currently a question if I pass in an RGBA and an alpha anyway |
I have also been considering the dict-approach briefly. However, I don't think it's a good design. From the user point of view it's quite cumbersome to write Conceptually, alpha is very closely related to color. Basically, you'll want to be able to make every color transparent. I think we should aim for a single entity that holds information on both. Some color specifications like RGBA already have that. The formal way would be an explicit class |
Currently, an explicit alpha overrides the alpha of a rgba tuple. (I think this is essentially a consequence of the semantics of |
So I never checked the signature of to_rgba(c, alpha) 🤦♀️ so maybe better documenting/adding an example would help. On the one hand I'm very pro an explicit 'Color' type, and it would essentially be doing to_rgba under the hood, but on the other not sure if we wanna go down that route yet. (ETA @ksunden what are your thoughts?) Maybe '(color, alpha)' is the most straightforward approach since it's basically a thin wrapper to calling to_rgba. Eta: also if me, Anthony, and Tim all sorta converged there, it'll be intuitive once it's advertised? |
I think the way forward here is to declare Concrete steps:
I assume everything else will fall in place then. |
My use case was HTML colors...I didn't know I could add alpha to them by concatenating an alpha value into hex until right now and I think "(anything considered a valid matplotlib color, alpha)" is more straighforward for the user than trying to special case a subset of the supported colors. Also, that is what's already supported in mpatches.Ellipse(ec, width=ew, height=eh, edgecolor=html_color, facecolor=mcolors.to_rgba(html_color, .10)) ETA: While I suggested an API change, maybe an alternative way to address this is another gallery example in the color section that shows how to use |
You can also only document |
it is documented: https://matplotlib.org/devdocs/api/_as_gen/matplotlib.colors.to_rgba.html but all the examples could just as easily be written using |
Here is an implemetation for ('color', alpha) if we want to go that route. Alternatively, I like the idea of adding an alpha example to the color gallery. I noticed the colors tutorial has a clear alpha example, although it doesn't use |
@j1642 sorry for dropping the ball on this, I think it's still an open question on whether we want to add this additional color specification (I'm 👍) but if you're interested please open a separate PR to add an example to the docs. ETA 2: if there's consensus, then also please add this spec to the table in https://matplotlib.org/devdocs/tutorials/colors/colors.html#sphx-glr-tutorials-colors-colors-py |
I'm also inclined to add this specification. While this is strictly redundant ( As opposed to my previous comment
I'm quite firm now that we should allow this and not do any artificial limitations. First, the strict equivalence |
Sorry haven't merged cause haven't had the time to investigate if the ci failure is related. |
Appveyor failure is unrelated, unfortunately was caught by #25209 so a conflict in the tutorial has arisen |
Thanks for all your patience w/ this(us) @j1642! |
No problem. Thanks everyone! |
Introduced by matplotlib#24691, merged shortly before matplotlib#24976 Not totally sold on the name 'RawColorType', but couldn't think of something I like better Noticed that one of the other type aliases was not documented, so fixed that while I was editing these two files
Introduced by matplotlib#24691, merged shortly before matplotlib#24976 Noticed that one of the other type aliases was not documented, so fixed that while I was editing these two files
Introduced by matplotlib#24691, merged shortly before matplotlib#24976 Noticed that one of the other type aliases was not documented, so fixed that while I was editing these two files
I just landed on the new example Ways to set a color's alpha value (which is really well indexed by search engines!). This new syntax seems pretty handy! Now here is my problem: I didn't know this was a new example/feature until I realized in didn't work on my setup. I don't know what is the policy for marking new features in examples, but perhaps the "version added" should be explicit in examples? |
Good point! We have from 3.7 tried to make it clear in the API documentation when things was added, but here it could clearly make sense to add a note in https://matplotlib.org/devdocs//users/explain/colors/colors.html#sphx-glr-users-explain-colors-colors-py that the last format is only available since 3.8. For individual examples, I am a bit more ambiguous (although I wouldn't block a PR with that). Not sure one can expect all to include it in a sensible way and at some stage one may want to expire that information in examples. It is a bit annoying though that the search engines are pointing to the the development docs. We used to have the opposite problem, that the hits were from 2.x... |
Interesting: I thought the other way round: put the version added to examples, because there is ample space to do that, while avoiding the clutter in the doc for color specification. In the end, there is still the fact that docs have a global version number. And I agree along with a "version added policy" should come a sensible expiration policy (I thinking here of some Scipy function I saw the other day which was quite cluttered by old "version added" marks)
I probably landed from Qwant, so it's probably not a massive issue. |
Fair point. On the other hand the color specification is sort of "the official color specification API doc", so should be there, although it doesn't render that nicely. I think my main "objection" is that I cannot really figure out a good way to get it into the example... """ Or a
at the start of the example? |
We used to have a banner on |
plan with the tags/gsod work is to start adding a tag for when a feature was added, possibly automagically |
Also, we might want to add |
PR Summary
In the Patch class, add the option of setting separate alpha values forCloses #24681.facecolor
andedgecolor
using a tuple,alpha=(facecolor_alpha, edgecolor_alpha)
.Add
(matplotlib supported color, alpha)
as a valid matplotlib color specificationPR Checklist
Documentation and Tests
pytest
passes)Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst