Skip to content
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

Incomplete Legends #94

Closed
zachcp opened this issue Nov 4, 2013 · 7 comments
Closed

Incomplete Legends #94

zachcp opened this issue Nov 4, 2013 · 7 comments

Comments

@zachcp
Copy link

zachcp commented Nov 4, 2013

Legends do not always contain all of the members in the legend. Here is an example with built in data where there should be 32 although only eight get plotted. I've tried a couple of examples and the legend seems to max out at eight. Most use cases won't need 32 but I often have more than eight items in a legend.

from ggplot import *
ggplot(aes(x= 'cyl', y='mpg', colour='name'), data=mtcars) + geom_point()
@jankatins
Copy link
Contributor

Thats suspiciously the same number as there are colors defined. Current HEAD lets you set more than 8 colors via ggplot(...) + scale_colour_manual(values=color_list), where color_list is a list of html encoded colors ['#12AB34',...].

If that works, this should probably be fixed by throwing an error when the last color is used in color_gen() (source) and using a palette which has more colors (not sure how...)

@zachcp
Copy link
Author

zachcp commented Nov 5, 2013

@JanSchulz Good catch. Thats exactly what it was. If you add 32 color to color_list it plots correctly (although 32 is too many items for the legend, especially since the legend does not wrap in any way).

The simple fix, as you say, is to make a default color pallete with more colors. Because the generators are called later in the ggplot.py file, i think the only solution is to make the color_list longer or to allow the color_gen function to sample an arbitrarily large color space.

How does the original ggplot do this? They have a consistent color scheme but I don't know how its mapped.

@jankatins
Copy link
Contributor

They know the number of items and then ask a function in the scale package for the number of colors. This would mean that the current implementation needs to change, as currently color generator does not know the number of values it needs to generate. I will have a look...

@zachcp
Copy link
Author

zachcp commented Nov 5, 2013

In ggplot.py the number of uniques are already calculated on line 325 with possible_colors = np.unique(mapping.color). I vote for completely replacing thecol_gen function with color generator that can accept an arbitrary number of values. Let me know if you want me to work on this.

@glamp
Copy link
Contributor

glamp commented Nov 23, 2013

Yeah this sounds good. I believe it has already been merged.

@jankatins
Copy link
Contributor

Nope: the problem is in https://github.com/yhat/ggplot/blob/master/ggplot/components/colors.py -> it recyles the last color, but the code is doing a reverse coding https://github.com/yhat/ggplot/blob/master/ggplot/ggplot.py#L340 which results that the second round color -> Value overwrites the first round color -> Value pair.

The fix is to a) precompute the number of colors needed and b) use a color generator which can give an arbitrary number of colors (that's what ggplot2 does)
OR
don't cycle to colors but throw an error if another color is requested and give a helpful error message how to set more colors.

I suspect that both variants are need for the case when you manually specify colors but they are not enough for the given values.

@glamp
Copy link
Contributor

glamp commented May 31, 2016

fixed in 0.9.3

@glamp glamp closed this as completed May 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants