-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Should we override the matplotlib color shorthands? #293
Comments
For what it's worth, I think this would be fine (and appreciated). Users who are concerned preserving the exact original styling of their matplotlib figures won't be using |
Here are some issues that come to mind:
|
I would integrate remapping of color shortcuts with seaborn's style changes and thus |
👎 I foresee this causing headaches on the mpl side. If you really want the ability to re-map the shortcuts on the fly I think it should be done upstream. More generally, I think much of the non-default-color/depends-on-pandas functionality of seaborn should be pulled upstream to mpl. |
Do you mean headaches for you guys (issues saying "wtf my plots changed!") or do you actually expect anything to break? If it's just changing the RGB tuples in the dictionary values (not adding or subtracting any entries), everything should run fine, right?
I agree though that kind of thing would have to wait until 2.0 right? And then anything else until 3.0? I think your "don't break tests on point releases" policy is very sound, but for stuff like this it's better to have an independent actor. |
The issue with hard-coded defaults is being slowly worked on with the style work in matplotlib, so for the purposes of this discussion, I would consider that being taken care of. As for what should 'r', 'g', and 'b' should mean, you do realize that 'red', 'green', and 'blue' are also available, right? The shorthand colors are the "pure" ones, while the longhand names are the HTML-defined colors. If you want to start messing around with how color strings are interpreted, go ahead and do that within seaborn and make sure that it is opt-in (I hate it when, just because a dependency of a dependency got imported, it starts mucking about with the packages I directly use). Now, what I could see happen is something along the lines of the CSS-like work (MEP 22, IIRC?). In there, maybe it could be possible to map stringy color names to hexcodes? Users could have colors like "dark1", "light3" and such, but they would be defined in the style sheet. Just me thinking out loud. |
I suspect it will mostly be people with broken plots not realizing that seaborn was reaching in and changing things. My issue is more that it violates encapsulation, than adding another knob. Once you start reaching in and mucking with the internals to that degree seaborn has gone from being a layer on top to a monkey-patch-implemented fork. I think many things (like the pallet context managers, the mutable color maps, what ever issues the syle package has that makes it annoying for you to use, the color pallets) can be pulled in in backwards compatible way. These are useful enough tools I would like to get them as widely distributed as possible. I also have the sense that there is a lot of over-lapping effort between pandas plotting, prettyplotlib, and seaborn. I think it would be worth everyone's time to centralize that effort. [edited to fix word salad] |
I agree with @tacaswell's objection to this. |
I think this is a valid concern, which is why I opened the issue instead of just doing it. But I also think this is a borderline case, and that actually more consistency would be gained from implementing it. And I do think that there's a difference between changing the behavior of a function and changing the lexicon used in a dictionary. Plus, it's not like it's called What I have in mind is quite restricted (although not fully worked out). Because the default seaborn color cycle is based on the matplotlib one, it would just replace each entry in the
Perhaps, although my hope is that it will be fairly obvious that it is congruent with everything else seaborn is doing. |
Except it won't actually be "taken care of" for users until 2.0, which I'm assuming is months if not years in the future (based on the fact that you seem to be in development for 1.5 at the moment). And won't be taken care of at all for people stuck on the 1.x series.
Yes. I am aware of how you can specify colors in matplotlib. My point is that it would be nice to have the shorthands map to useful colors. I'd much rather write I don't really see what's "pure" about "b", "r", "g". If anything I see it as the opposite -- I would never mess with what the HTML color names get mapped to because that has a very clear definition. But I don't think "b" obviously means RGB (0, 0, 1), and the RGB color space has no particular relationship to human color vision. I'll point out too that the shorthands aren't completely "pure" in the sense of RBG space even; for example, "g" is not (0, 1, 0) but (0, .5, 0), presumably because the former is really obnoxious. |
Whoops, wrong button. |
A middle ground would be a function to do this that people have to explicitly call independently of other changes to the default color cycle. |
I think we are talking past each other. The issue is not that the ability to re-define the meanings of color short cuts, I am tentatively on board with this, the issue is that the machinery for this should live up-stream. |
Ah! Gotcha. That makes sense. |
Though I would still want a seaborn interface on top of that to go from the named seaborn palettes to particular values for the shortcuts, of course. |
It looks like in the present mpl color dictionaries, r, g, and b correspond exactly to red, green, and blue. The minor difference is that c, m, and y use coefficients of 0.75 where cyan, magenta and yellow use 1.0. You might not like those colors, but they are conventional definitions; I would leave them alone. It seems to me that even within mpl, messing with the present name:color mappings is not a good idea. It sounds like what is needed is a facility for any default color to be set (as is the case with the color cycle), and for there to be a separate facility allowing the user to assign non-conflicting names to colors, with or without seaborn. Then seaborn could define "sr", and set this as the default wherever "r" was the original mpl default. I think this could even work with single-letter colors other than rgbcmykw, so one could define a color "x", and then |
This isn't the main point here, but we don't perceive colors in RGB channels, so I don't really think that calling (1, 0, 0) "exactly red" makes any sense. |
The broader point about "monkey patching" is this: Python as a language has ways to afford changes and other ways to restrict them. If you want to signal that people shouldn't mess with this color dictionary, I would suggest either renaming it |
This does not seem very useful. The goal is not to define colors with completely obscure names, it is to bring the colors referred to by a specific set of shorthand tokens in line with the rest of the aesthetic defaults. |
I agree it is not the main point; but does this mean you think it is also OK to redefine "red", the html value? Python, monkey-patching, and mpl: yes, those are reasonable suggestions, among the vast number of ways mpl code could be improved. MPL was not designed from the top down as a beautiful edifice, with perfect foresight as to what should be private and what public. |
OK, you are dead-set on manipulating the meanings of rgbcmykw, and this might indeed be a good idea. If so, it can be done with an interface added to mpl, as I think @tacaswell is advocating; it seems like it should be quite simple. |
No, because that has a specific meaning. Named color strings in matplotlib are interpreted as lookup values in the HTML color table. I think it's aesthetically unfortunate that "HTML red' maps to (1, 0, 0), but I wouldn't go into the On the other hand, from the user's perspective is "b" a lookup into a specific color lexicon, or should it correspond with the first color in the default cycle? People might be split in what they expect, but the latter both feels more consistent and lets people using seaborn specify colors with a very useful shorthand. (And it fixes the issue with hard-encoded defaults). |
So, if the issue is to have the color in the color cycle match a color used The only thing that remains is the issue of the default values of the On Sat, Oct 4, 2014 at 3:38 PM, Michael Waskom [email protected]
|
I don't know if this is the right thread, but I find Seaborn's behavior regarding shorthand linestyle to be frustrating. The plot undoubtedly looks nicer, but lacks the markers, which can be incredibly useful as a reference. I'm aware that sns.pointplot() will provide something similar, but it is confusing as a long-time matplotlib user, and aspiring seaborn user, for this very easy plotting shorthand to lose its functionality. |
Thanks, I see the fix in 0.5.1, sorry to muddle the current thread. |
Matplotlib lets you specify colors like
"b"
for blue,"r"
for red, etc. which is nice. But, those colors are mapped to the corners of RGB space, which, bleh.This is additionally problematic as some functions (like
plt.scatter
) hardcode these values as default.It occurs to me that seaborn could override this by messing with the values in the
mpl.colors.ColorConverter.colors
dictionary. But that might be too much manipulation?Opening this issue for discussion.
The text was updated successfully, but these errors were encountered: