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

can jointplot visualize different classes? #365

Closed
hdmetor opened this issue Nov 14, 2014 · 8 comments
Closed

can jointplot visualize different classes? #365

hdmetor opened this issue Nov 14, 2014 · 8 comments
Labels

Comments

@hdmetor
Copy link

hdmetor commented Nov 14, 2014

Is it possible to have different color for different classes in joinplot? Something like

df = pd.DataFrame(np.random.randn(100, 4), columns=list('ABCD'))
df['category'] = np.random.randint(0, high  = 5, size = 100)
sns.jointplot('B','A', data = df, color='category')

where a different color is used for each different value in the category column. Even better, would be possible to have a color for each value after a function is mapped to the column?
In my example, assume I would like to have a color for odd values, and another one for even values of the column, i.e.

sns.jointplot('B','A', data = df, color='category', map = (lambda x: x % 2))
@mwaskom
Copy link
Owner

mwaskom commented Nov 14, 2014

Not easily, no.

@mwaskom
Copy link
Owner

mwaskom commented Nov 14, 2014

Actually I guess that's not strictly true, for kind=scatter you can pass a vector of colors to c in scatter_kws. But it doesn't have general hue-based grouping like lmplot does.

@mwaskom
Copy link
Owner

mwaskom commented Nov 14, 2014

See my answer to #294 for more ideas on what you could do.

@hdmetor
Copy link
Author

hdmetor commented Nov 20, 2014

Ok, thanks a lot.
I would be a cool feature to add

@mwaskom
Copy link
Owner

mwaskom commented Nov 21, 2014

It could be useful, although for several of the jointplot styles (like hex or kde) it wouldn't make a lot of sense. JointGrid is pretty straightforward to use directly so I don't want to add a lot of complexity to jointplot right now.

@mwaskom mwaskom closed this as completed Nov 21, 2014
petebachant added a commit to petebachant/seaborn that referenced this issue Jul 9, 2015
@ruxi
Copy link

ruxi commented Mar 6, 2018

I wrote a gist on how to do this:

https://gist.github.com/ruxi/ff0e9255d74a3c187667627214e1f5fa

@efharkin
Copy link

efharkin commented Aug 4, 2020

@mwaskom would you consider a PR to add support for hue in jointplot and/or JointGrid, or at least some changes to JointGrid.plot_{joint,marginals} to support some of the categorical plotters? (As of now, joint_grid.plot_marginals(sns.boxplot, hue=whatever) raises an error about an unexpected keyword argument used to set the orientation. Seems like an easy fix and I'd be happy to work on this.)

It seems like there's a lot of demand for increased support for visualizing the distributions of categorical data (#861, #1486, this question). @ruxi's gist is a nice solution, but it would be great to have this behaviour or something similar directly in jointplot/JointGrid. A potential drawback of folding this behaviour directly into JointGrid is that the joint axis might not look very good if we use certain styles (eg hex), but I think this could be solved by raising an error.

Let me know if this fits with how you'd like to see jointplot and JointGrid used and I can work on a PR.

@mwaskom
Copy link
Owner

mwaskom commented Aug 21, 2020

xref #2210

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

No branches or pull requests

4 participants