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

Aggregate data in a specific column #52

Closed
JKalnins opened this issue Mar 19, 2020 · 3 comments
Closed

Aggregate data in a specific column #52

JKalnins opened this issue Mar 19, 2020 · 3 comments

Comments

@JKalnins
Copy link

Hi,

I saw #17 explaining how to use kind="values and x_range in order to use aggregated data, but I'm finding it hard to combine this functionality with setting a specific column for output.
I've got a dataset with a set of locations (lat & long) with measurements taken at each point giving a numerical value.

     lat        long        val

    001.012    001.01        11

    001.431    004.49        25

    001.769    008.72        04

    002.100    001.32        03

    002.504    003.49        17

    ...

(rubbish formatting but it gives you the right idea)

I've binned the y-values (lat) using pd.cut to give a lat_bins column and plotted this using:

fig, axes = jp.joyplot(df, by="lat_bins", column="long")

But what I'd like to have is something like:

fig, axes = jp.joyplot(df, by="lat_bins", column="long", kind="values", x_range=<some range>))

This displays a plot without any data; and no error appears when running the code so I don't know what to fix. The goal is to have a plot at each latitude showing the distribution according to longitude. (i.e., the dataset shown above would have the first layer showing 11 - 25 - 4 going across from 001 to 008 lat.

@leotac
Copy link
Owner

leotac commented Apr 7, 2020

Hi! Not sure I fully understood what you want to obtain here.
One thing I can say, though, is that kind="values" is not meant to be used with "by" - it's meant to be used only if you want to do all the binning yourself (and no smoothing will be done by joypy).
So you would need to have a dataframe with lat_bins as rows, and lon_bins as columns, with the grouped val in the cells. Does it make sense?

Example with iris (just renamed the columns to be similar to your case):

%matplotlib inline
df = iris[["SepalLength","SepalWidth","PetalLength"]].copy()
df.columns = "lat", "lon", "val"
df["lat_bin"] = pd.cut(df.lat, 10)
df["lon_bin"] = pd.cut(df.lon, 10)
grouped = df.groupby(["lat_bin","lon_bin"])["val"].sum().fillna(0).unstack(1)
joypy.joyplot(grouped, kind="values", x_range=[0,10]);

joypy

@leotac
Copy link
Owner

leotac commented Apr 7, 2020

Then you're going to need to do some work to manually fix the x and y ticks as you prefer.

@JKalnins
Copy link
Author

Thanks, that helped!

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

2 participants