Code Monkey home page Code Monkey logo

Comments (7)

jankatins avatar jankatins commented on August 17, 2024

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...)

from ggpy.

zachcp avatar zachcp commented on August 17, 2024

@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.

from ggpy.

jankatins avatar jankatins commented on August 17, 2024

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...

from ggpy.

zachcp avatar zachcp commented on August 17, 2024

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.

from ggpy.

glamp avatar glamp commented on August 17, 2024

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

from ggpy.

jankatins avatar jankatins commented on August 17, 2024

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.

from ggpy.

glamp avatar glamp commented on August 17, 2024

fixed in 0.9.3

from ggpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.