-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
pyplot.scatter() does not cycle colors #3041
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
Comments
Sorry for this not getting a response for so long. Tagged an 1.4.0, but it might slip. I am not very enthusiastic about adding this (I think of scatter as in a different class that the other plotting tools as it can be colormapped). |
I agree; is there any compelling use case for having scatter cycle the color? Sufficiently compelling to change long-established behavior? |
I'm using scatter() to plot independent variables, as such I expect each call to have it's own color automatically. I came to expect this behavior after using R mostly (both base graphics and ggplot). In fact, I would expect every "high level" plotting command to cycle colors by default, since cycling colors or choosing a specific color from the RC index (from the user's perspective) is not convenient. But it would be perfectly fine for me to have another command for having scatter plots. It's a shame that I have to use another library on top of MPL just for such convenience. |
If you are not varying the size of the markers your are far better off using If you are writing loops anyway throwing an extra variable in is not a huge deal (and your not using the pyplot interface in a script are you? ;) ). |
I use pyplot all the time, even in scripts :). Only very few methods using the color cycle at the moment (plot and hist, anything else?) and improving this would be nice, but i think this a 2.0 change due to |
@Tillsten The danger of using pyplot in scripts is that if the state machine gets out of sync you can get some really strange results. There is a genre of questions on SO that consist of 'the state machine hates me!'
is less typing, gives you better control, and gives you access to more functions (as pyplot does not wrap everything). |
I know, but a) the state is really small: current axis and figure b) i even use pylab 😱, so it is less typing. Note, this is for making figures only, for complicated cases and interaction i change to the oo-interface. But i complete agree, that beginner should learn learn the oo-interface! |
Or just understand what the difference is. It's not so complicated. When I teach mpl, I introduce the Axes methods, and then demonstrate that pyplot is just a think wrapper to those. At the end of it, newbie Python developers can describe the pros&cons of pyplot, which I think is a result... (http://nbviewer.ipython.org/github/SciTools/courses/blob/master/course_content/matplotlib_intro.ipynb). |
I think we're losing the focus on the issue here. scatter() seems high-level enough to me, especially considering that an useful addition to scatter would be the option to have some jitter, which would not be very logical on plot(). I see the argument of backward compatibility, but I was hoping there was some direction in cleaning the API a bit. If not now, a new relase? The choice of colors is not uniform (box plots for instance do not respect the color index), there's no decent way to get/set the current index color conveniently, and generally speaking I keep having to look at the documentation all the time due to the lack of consistency here and there. |
@wavexx I think we all agreeing, that more functions should use color cycling. But there |
I like this suggestion. Though if we introduce this variable, I'd like to know some things:
I never specify colors directly on the various calls. I copy the values myself from the RC into a variable, and keep reusing the variable to have consistent colors. I'm not sure if an integer (as opposed to float) could be distinguished on it's type() and be accepted as a valid color, in the form of rc[color_cycle][index % len(rc[color_cycle])] as gnuplot does. I find this behavior very convenient, especially when producing consistent plots for the same publication, and changing style later is easier. |
Regarding jitter, that has come up before and it is very unlikely that will get added. The problem with the way we do it now (keeping the color cycle information in the axes) is that every plotting function needs to have this logic. I think providing a class like:
and stripping this logic from axes/axes methods is a more maintainable path. |
On 05/21/2014 04:41 PM, Thomas A Caswell wrote:
On one-dimensional data, when comparing groups where data is exactly As for determinism, you could even set a fixed seed. That being said, I used jittered plots maybe three times in my career. |
There is a slight typo in the code above This likes you do things like
and then you can do cute things like just drop in
or even drop in a
|
I don't like the api too much, ich would prefer to have the colorcycler as an simple axis attribute.
|
Just to chime in a bit... don't forget about the possibility to cycle other Thomas's example is intriguing, but it has a fundamental drawback (in my On Thu, May 22, 2014 at 7:46 AM, Till Stensitzki
|
Changing the cycling from implicit to explicit was the goal. The To be clear, this was an idea I had so I wrote it up. It seems to work, but I am not advocating this to replace the current color cycle (yet), but it does solve the problem of the OP. It is probably a better path to put that logic in a decorator which we can then wrap functions in, and add |
A decorator! Why didn't I think of that before?! This would allow @tcaswell, you are a genius!!! I might have some time tonight to slap On Thu, May 22, 2014 at 5:02 PM, Thomas A Caswell
|
@WeatherGod Given that I had decorators on my mind for your comment on #3070 I think you did think of this before. I don't think we want to try to fit this in for 1.4, re-tagging as 1.5.x |
That is true, but I just never thought about using decorators for color There is going to be some difficulties with recognizing and handling |
I like the overall concept, and using decorators. |
We should also pull @olgabot (prettyplot), @JanSchultz (yhat ggplot), @mwaskom (seaborn), and @tonyyu (style sheets) in on this conversation. I any work on this should make their lives easier so getting their input sooner rather than later would be good. I also think that the discussions of how/if to change rcparams (ex #2637 ) should be folded in with this. How many of you all are going to be at scipy? @wavexx Sorry for completely hi-jacking your (seemingly simple) issue to be 'refactor all the things!' |
Again meant to ping @JanSchulz, sorry for the noise. |
I won't be at scipy. Whether or not |
I will be at SciPy, and my vote is to transition to fixing the default for On Fri, May 23, 2014 at 11:32 AM, Michael Waskom
|
We don't use color cycling but either specify our own colors (which uses mpl color cycling in some themes) or use just one default color. What would be nice is to specify more than one color/point style (linestlye/...) during the |
@JanSchulz I think #4258 + discussion at end of #3818 will get you towards what you want. I am closing this issue as it has been quiet for over a year and what of this thread will be addressed is being is being addressed elsewhere. |
This works, taken straight from my own code.
I randomise the
Finally if you are feeling like a risk taker then replace as As a side comment it will break if you have more lines than colours. I leave that to someone else to figure out as I don't require it. |
This actually went in to 2.0 via #6291 You should checkout the 2.0.0b1 release. |
It looks like MPL is inconsistent in color cycling.
I would expect scatter() to cycle the current color as plot() does.
The text was updated successfully, but these errors were encountered: