matplotlib - Python ViolinPlots -
i'm trying make violin plot this data set.
i want x axis first column (time) in total seconds. , left half of violin askbidavg while right half grpavg there different method using hue because examples saw takes column has 2 unique values. have many different values in there. causing problem. using 1 minute increments calculate total seconds(). either in seaborn or matplotlib. current code i'm using is:
sns.violinplot(x="time",hue=["askbidavg", "grpavg"] ,inner ="quartiles" , linewidth= 1,split=true , data=df ) however, throws error hue cannot more 2 values.
in order plot want, need perform little transform of data.
you have time column - 1 fine second column should hold y values (it have of number values) there should column tells whether askbidavg, or grpavg
time variable value 0 18000 askbidavg -0.000019 1 18000 askbidavg -0.000024 2 18000 askbidavg 0.000019 ... ... ... ... 76 18004 grpavg -0.000019 77 18005 grpavg -0.000005 78 18005 grpavg -0.000012 79 18005 grpavg 0.000002 pandas has nice function can you.
import pandas pd df = pd.read_csv("/users/james.natale/downloads/yourdata.csv",index_col=false,header=0) df = pd.melt(df, id_vars=['time'], value_vars=['askbidavg', 'grpavg']) import seaborn sns sns.set(style="whitegrid", palette="pastel", color_codes=true) # draw nested violinplot , split violins easier comparison sns.violinplot(x=df['time'], y=df['value'], hue=df['variable'], split=true, inner="quart") sns.despine(left=true)
Comments
Post a Comment