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

Different colors or colormaps for different data series #215

Closed
lorenzoamir opened this issue Oct 10, 2024 · 11 comments
Closed

Different colors or colormaps for different data series #215

lorenzoamir opened this issue Oct 10, 2024 · 11 comments
Labels
enhancement New feature or request

Comments

@lorenzoamir
Copy link

Hi, thank you for this package.
I was wandering if it was possible to have the colors (or colormaps) represent categorical data. For example, in the minimum and maximum temperature example in the documentation, have all data regarding minimum temperature in blue and data regarding maximum temperatures in red.
I made an example image of what I would like to achieve:
image
Thank you

Copy link

Thank you for submitting your first issue with us! 🎉

Our response time may vary, but we will get back to you as soon as possible.

To help us help you, please make sure you have provided all the necessary information in your issue's description. 🙏

If you'd like to contribute to the project (maybe even fix the issue yourself!), please check out our contributing guidelines.

Welcome aboard! 🚀

@tpvasconcelos tpvasconcelos added the enhancement New feature or request label Oct 10, 2024
@tpvasconcelos
Copy link
Owner

Ciao @lorenzoamir! Thanks for submitting this feature request and providing a clear example plot right away! I love the idea and I've thought about implementing this in the past but never had the time. I'll try to have a look at it and make a quick assessment of the effort required.

For these sort of changes, I always have to consider backwards compatibility, updates to the current documentation, user experience, how the API should look like and its impacts on the long-term maintainability of the project, etc...

If you already have a good idea of how you think the API could look like from the user's perspective let me know.

@tpvasconcelos
Copy link
Owner

From the top of my head, we could either somehow tap into the existing colorscale and colormode parameters to allow for this behaviour, or add an extra colors parameter that allows arbitrary colors to be passed for each individual trace.

I think I prefer the first option as adding yet anther "color" parameter would make things more confusing for end users, given that we already have colorscale, colormode, and coloralpha.

@tpvasconcelos tpvasconcelos pinned this issue Oct 10, 2024
@lorenzoamir
Copy link
Author

I agree. Maybe something like passing a list of colors to the colorscale parameter could work. Unfortunately I really don't have the time to work on it at the moment.

@tpvasconcelos
Copy link
Owner

I think that the change that requires the least amount of changes is to introduce a new colormode (e.g. trace-index-row-wise) that will take the index of each row's trace (0 and 1 in your example) and use that to grab colors form a colorscale.

In your example, the colorscale would have these two entries only:

(
    (0.0, "red"),
    (1.0, "blue"),
)

I'll try to work on a draft pull request today.

@tpvasconcelos
Copy link
Owner

I got the example bellow with these two settings:

fig = ridgeplot(
    # ...
    colorscale=(
        (0.0, "rgb(20, 20, 255)"),
        (1.0, "rgb(255, 20, 20)"),
    ),
    colormode="trace-index-row-wise",
    # ...
)

image

@tpvasconcelos
Copy link
Owner

@lorenzoamir what do you think of this interface for now?

@tpvasconcelos
Copy link
Owner

@tpvasconcelos
Copy link
Owner

Ideally, ridgeplot should probably use the same conventions used by Plotly express for both continuous and discrete coloring options.

Here are the official references:

I'll create a new issue for this.

@tpvasconcelos
Copy link
Owner

@lorenzoamir I've merged #224 so I'll close this issue. Let me know if this solution worked for you :)

For others coming here, I'm moving the more general discussion around more color options to #226.

@tpvasconcelos tpvasconcelos unpinned this issue Oct 16, 2024
@tpvasconcelos
Copy link
Owner

FYI: In the latest version of ridgeplot you can use the following simplified notation:

import numpy as np
from ridgeplot import ridgeplot

# Generate some sample data
my_samples = [
    [
        np.random.normal(n, size=600),
        np.random.normal((n + 1), size=600),
    ]
    for n in range(4, 0, -2)
]

# Create a ridgeplot and color the traces per row as red and blue
fig = ridgeplot(
    samples=my_samples,
    colorscale=["red", "blue"],
    colormode="trace-index-row-wise",
    coloralpha=0.9,
    linewidth=0,
)
fig.update_layout(height=450, width=800)
fig.show()

image

Again, for the ones interested, the progress in adding more coloring modes can be found in #226

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants