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

Colour by another column of data within a data array (pandas or numpy) #109

Open
timrifts opened this issue Jul 23, 2019 · 2 comments
Open

Comments

@timrifts
Copy link

Hi,

Great tool for making ternary plots! It'd be great for visualisation of any trends if the points within a given tax.scatter(...) line could be given more than one colour to allow for datasets to be coloured by something else (another variable in the dataset for example). E.G after a Pandas import of...:
Name Depth V1 V2 V3
0 Unit1 14 10 20 70
1 Unit2 15 50 50 0
2 Unit3 16 25 20 5
3 Unit4 18 50 25 25

Could be plotted according to V1,V2,V3 proportions and coloured by either Name (i.e grouping into identical groups) or according some other parameter (e.g Depth).

To do this at the moment would require lots of individual tax.scatters which is great if you want the flexibility of changing shape etc but can be cumbersome with larger datasets. Apologies if this is already there or a other simple solution - only a couple of weeks into my Python life!

Cheers,
Tim

@marcharper
Copy link
Owner

Hi, thanks for the suggestion. I've considered supporting dataframes, the main reason that the library currently does not support them is simply because most of it was written before pandas became common.

It should not be hard to write a function to handle this behavior in the meantime, something like:

def dataframe_to_scatter(df, xcol, ycol, zcol, colorcol):
    fig, tax = ternary.figure()
    colors = list(sorted(set(df[colorcol].tolist())))
    for color in colors:
        subdf = df[df[colorcol] == color]
        xs = subdf[xcol].tolist()
        ys = subdf[ycol].tolist()
        zs = subdf[zcol].tolist()
        tax.scatter(zip(xs, ys, zs), color=color)
    return tax

@timrifts
Copy link
Author

timrifts commented Jul 26, 2019 via email

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

No branches or pull requests

2 participants