0

I am able to plot each box plot for each of my subfolders but I do not know it does not make all plots together while I'm plotting through a for loop and also when I try to label them it is not possible to use "labels=directory". I have read the answer of this post also I have seen this post but it looks different since I do not want to put numbers as my X-Axis neither to set the axis manually by my own. My X-Axis should be the name of each directory

import os
import matplotlib.pyplot as plt

sns.set(style="darkgrid")
#matplotlib qt

root = r'/home/hossein/Desktop/Out/INTERSECTION/BETA 15'
xx=[]
percentage=[]
my_list = os.listdir(root)
my_list =  [file for file in my_list if os.path.isdir(os.path.join(root, file))]

for directory in my_list:

    CASES = [file for file in os.listdir(os.path.join(root, directory)) if file.startswith('config')] 
    if len(CASES)==0:
        continue
    CASES.sort()

    percentage=[]

    for filename in CASES:

        with open(os.path.join(root, directory,filename), "r") as file: 

            lines = file.readlines()
            x = [float(line.split()[0]) for line in lines]
            y = [float(line.split()[1]) for line in lines]

            g = np.linspace(min(y),max(y),100)

            h = min(y)*0.9
            t = max(y)*0.9

            xx=[]

            for i in range(1,len(x)):

                if (y[i] < h or y[i] > t):
                    xx.append(x[i])

            percent = len(xx)/len(y)

            percentage.append(percent)

    green_diamond = dict(markerfacecolor='g', marker='D')

    plt.boxplot(percentage,flierprops=green_diamond,whis=0.001)

    plt.show()

Mir.Emad
  • 83
  • 8
  • you could create minimal working code with some example data in code so we could run it. – furas Jun 09 '20 at 21:33
  • @furas You mean deleting unnecessary information from codes or designing an example similar to this? The first solution that came to my mind was designing a `for loop` to read in each step – Mir.Emad Jun 09 '20 at 23:02
  • @Mir.Emad furas revers to the fact that we cannot run your sample because we do not have your data. It would be nice if you could add some data, e.g. as a couple of python lists. So anybody can just copy and paste and try your code. – Christian K. Jun 09 '20 at 23:07
  • 1
    create example which makes the same problem but which we could copy-paste and run. And maybe when you will create example then you see where is problem - reducing code is good method to debug it. – furas Jun 10 '20 at 00:28
  • @furas It's right and I will do that, just one thing which is, in my case, due to the reading from directory, it is difficult to make a sample. I can do without reading through a directory, just by faking up some lists. – Mir.Emad Jun 10 '20 at 08:52

0 Answers0