0

first I need to filter data then plot each group separately and save files to directory

for id in df["set"].unique():

  df2= df.loc[df["set"] == id]

   outpath = "path/of/your/folder/"


   sns.set_style("whitegrid", {'grid.linestyle': '-'})
   plt.figure(figsize=(12,8))
   ax1=sns.scatterplot(data=df2, x="x", y="y", hue="result",markers=['x'],s=1000)
   ax1.get_legend().remove()
   ax1.set_yticks((0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5), minor=False)
   ax1.set_xticks([0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.6], minor=False)

   fig = ax1.get_figure()
   fig.savefig(path.join(outpath,"id.png",dpi=300 )

1 Answers1

0

This worked for me but it is very slow

groups = df.groupby("set") 


for name, group in groups: 

    
    sns.set_style("whitegrid", {'grid.linestyle': '-'})
    plt.figure(figsize=(12,8))
    
    ax1=sns.scatterplot(data=group, x="x", y="y", hue="result",markers=['x'],s=1000)
    ax1.get_legend().remove()
    ax1.set_yticks((0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5), minor=False)
    ax1.set_xticks([0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.6], minor=False)
    
    fig = ax1.get_figure()
    fig.savefig("directory/{0}.png".format(name), dpi=300)
    
  • can someone please suggest any faster way? –  Feb 11 '21 at 17:51
  • How? We don't know your data structure. Please read [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – Mr. T Feb 11 '21 at 17:56