我已经为目录内的不同子文件夹绘制了一个图表,我想根据文件夹的名称为每个图表添加一个图例。我的意思是,情节图例是根据文件夹的名称编写的。绘图代码如下:
from __future__ import division
import sys
import os
import numpy as np
import matplotlib.pyplot as plt
import glob
import seaborn as sns
from scipy import stats
from scipy.stats.kde import gaussian_kde
root = r'C:\Users\Hasan\Desktop\output\new our scenario\beta 15\test'
mean_cu=[]
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
maxnum = np.max([int(os.path.splitext(f)[0].split('_')[1]) for f in CASES])
CASES = ['configuration_%d.out' % i for i in range(maxnum)]
mean_cu=[]
for i, d in enumerate(CASES):
a = np.loadtxt(os.path.join(root, directory,d)).T
num = os.path.splitext(d)[0]
local_cu = np.abs(a[4])
mean_curv.append(np.mean(local_cu))
pdf = stats.norm.pdf(mean_cu)
Time = np.arange(0,len(pdf))
plt.plot(Time,pdf)
倚天杖
相关分类