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

Colourmap depending upon a third variable or passing a list of colors #34

Closed
sharmaabhishekk opened this issue Jun 28, 2019 · 3 comments

Comments

@sharmaabhishekk
Copy link

I created this joyplot below
D9-y6IhUIAAQvLzpng

However, for every one of the 20 teams on the y-axis, I want to colour them according to a Pandas dataframe column which contains a total value for every team. I was wondering if the colourmap could be customised to colour the plots according to a third data variable - either a Pandas Series, numpy array, or something similar.
So for my dataframe the Total would look like this:

   Team     Total
Angers      356
Monaco      452
PSG         501
Lyon        369

Here's what works as expected:

fig, axes = joypy.joyplot(df, by="Team", column="Minute", figsize =(10,16), x_range = [0,94], linewidth = 1,
legend=False, colormap = color ,  title= "When do teams in Ligue 1 take their shots?")

Here are a few solutions I tried and failed at. Firstly, I created a colormap for the entire series depending on the Total data using this -

norm = plt.Normalize(group_df["Total"].min(), group_df["Total"].max())
cmap = plt.cm.viridis
sm = matplotlib.cm.ScalarMappable(cmap=cmap, norm=norm)
ar = np.array(group_df["Total"])
Cm = cmap(norm(ar))
sm.set_array([])

1 - Passing the customised colourmap in the function

fig, axes = joypy.joyplot(df, by="Team", column="Minute", figsize =(10,16), x_range = [0,94], linewidth = 1,
legend=False, colormap = Cm ,  title= "When do teams in Ligue 1 take their shots?")

2 - Passing the array of RGBA tuples to the colour

color = np.array(tuple(map(tuple,Cm)))
fig, axes = joypy.joyplot(df, by="Team", column="Minute", figsize =(10,16), x_range = [0,94], linewidth = 1,
legend=False, color = color ,  title= "When do teams in Ligue 1 take their shots?")

3 - Using the axes handles to set_facecolor - I saw this here

for col, ax in zip(Cm, axes):
        ax.patch.set_facecolor(col)

1 and 2 threw up an invalid RGBA argument and Assertion Error respectively. 3 had no error but the change was not reflected in the resulting plot. All I could gather is that currently, there's a no way to pass a list of colors (with a size similar to the grouped y-axis) or a customised colormap. If that's true, does there exist a work-around which I could implement? Or could a new feature be added?

@ImportanceOfBeingErnest

I answered this at https://stackoverflow.com/questions/56778635/how-to-change-colormap-in-joypy-plot/56817161#56817161

@leotac
Copy link
Owner

leotac commented Sep 7, 2019

Nice, is it ok if I add your code in the examples?

@leotac leotac closed this as completed Sep 7, 2019
@ImportanceOfBeingErnest
Copy link

Sure, do whatever you want with it.

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