我正在编写一个脚本来生成python3中学生的GPA的多个绘图。以下是数据集。
Roll No GPA 1 GPA 2 GPA 3 GPA 4 GPA 5 GPA 6
BE/5746/07 7.82 8.29 8.53 8.76 9.31 8.88
BE/CIVIL/5777/07 7.18 7.29 7.82 8.24 8.94 8.69
BE/CIVIL/5577/07 7.29 7.41 8.18 8.18 8.75 7.63
BE/CIVIL/5753/07 7.29 7.24 7.47 7.65 8.13 8
BE/5782/07 6.88 7.41 7.41 7.59 8.25 7.75
BE/CIVIL/5524/07 6.53 6.82 7.33 7.22 8.06 7.75
BE/5763/07 6.65 6.94 7.35 6.76 8.47 6.94
BE/CIVIL/5780/07 6.82 7.33 7.06 7.06 8.31 6.78
BE/CIVIL/5760/07 6.47 7 6.88 6.39 7.59 6.56
BE/CIVIL/5772/07 6.17 7.06 7.23 6.31 6.76 6.56
BE/CIVIL/5787/07 6.24 6.53 6.35 6.35 7 6.87
BE/CIVIL/5758/07 6.11 6.71 6.47 6.35 7.06 6.25
出于某些次要原因,很多图只是被复制,而我在不同的行上得到的是相同的图。我保存的胶卷编号名称中删除了“ /”的图像。我使用的代码是-
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style = "darkgrid")
raw_data = pd.read_csv("student alumni data.csv")
raw_data['img_name'] = raw_data['Roll No'].apply(lambda x: str(x).replace("/", "") + ".png")
i = 0
plt.ylim(4, 10)
for index, rows in raw_data.iterrows():
x_list = ['GPA 1', 'GPA 2', 'GPA 3', 'GPA 4', 'GPA 5', 'GPA 6']
y_list = [rows['GPA 1'], rows['GPA 2'], rows['GPA 3'], rows['GPA 4'], rows['GPA 5'], rows['GPA 6']]
sns.set(style = "darkgrid")
sns_plot = sns.barplot(x=x_list, y=y_list, palette="Blues_d").set_title("GPA's of all semesters")
sns_plot = sns_plot.get_figure()
sns_plot.savefig("img/" + str(rows['img_name']))
print("Done fig : ", i)
del sns_plot, x_list, y_list
i += 1
请帮助我找出错误
答案 0 :(得分:1)
因此,我认为问题在于,每次都将覆盖该图,并且它们彼此之间都被绘制。
如果您更改行:
plt.clf()
收件人:
del
在写入图像后,它应该清除内存中的图,并应提供所需的结果。
for (int q = 1; q < 3; q++) {
switch (q) {
case 1:
temp = new ArrayList<>();
temp.add("case1");
methodA();
list.add(temp);
break;
case 2:
temp = new ArrayList<>();
temp.add("case2");
methodA();
list.add(temp);
break;
}
}
行是不必要的,因为所有这些变量都在循环范围之内,因此在每次循环迭代后都将其删除。