【发布时间】:2021-03-21 00:58:01
【问题描述】:
我正在尝试利用 seaborn 绘制线图的潜力,但似乎我不断收到错误“TypeError: unhashable type:'list'”,我知道数据框值存在问题准确度是列表,虽然我不知道如何根据索引正确绘制列表(我也将其放入名为“Accuracy_Indexes”的列表中)。基本上,我只是想在 X 轴上打印每个“精度”,在 Y 轴上打印它们的索引,色调为“Bin”。所以它是 X 和 Y 轴大小相同的两个列表。不确定 Catplot 是否是获得诸如线图之类的正确图,但我收到警告说它已经过时并且将来会被删除。
import pandas as pd
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
N=7
Accuracy_Indexes = list(range(1, 5))
df = pd.DataFrame({'Bin': np.random.randint(1,10,N)})
TheList = []
for item in range(N):
TheList.append([item+1, np.random.random_sample(size=len(Accuracy_Indexes)).tolist()])
print(TheList)
df = pd.DataFrame.from_records(TheList,columns=['Bin','Accuracies'])
print(df)
g = sns.catplot(x=Accuracy_Indexes, y='Accuracies', hue="Bin",
data=df, height=5, aspect=.8)
plt.show()
感谢您的建议。
【问题讨论】:
标签: python-3.x list plot seaborn