gpt4 book ai didi

python - 在 python 中使用 seaborn 绘图复制绘图

转载 作者:太空宇宙 更新时间:2023-11-04 04:36:33 25 4
gpt4 key购买 nike

我正在编写一个脚本来生成 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

由于一些次要原因,许多地 block 只是被复制,而我得到的是不同行的相同地 block 。我正在使用删除“/”的卷号名称保存图像。我使用的代码是 -

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

请帮我找出错误

最佳答案

所以我认为问题在于情节每次都被覆盖,并且它们都在相互策划。

如果你改变行:

del sns_plot, x_list, y_list

收件人:

plt.clf()    

它应该会在您写入图像后清除内存中的绘图,并且应该会为您提供所需的结果。

del 行是不必要的,因为所有这些变量都在循环范围内,因此它们将在每次循环迭代后被删除。

关于python - 在 python 中使用 seaborn 绘图复制绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51571625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com