【发布时间】:2021-07-14 11:43:22
【问题描述】:
我试图用 seaborn 创建一个情节,但我遇到了一个错误:
*** ValueError: If using all scalar values, you must pass an index
在我的程序中,我从 XFOIL 读取了一个输出文件,并试图绘制其结果以进行检查。
XFOIL 文件格式:
# x Cp
1.00000 0.24276
0.99818 0.23883
0.99591 0.22657
0.99342 0.21421
0.99066 0.20128
0.98759 0.18802
0.98413 0.17434
0.98020 0.16018
0.97569 0.14544
0.97044 0.12999
0.96429 0.11374
0.95703 0.09661
### **(the file is big, and I will not transcript it completely here)** ###
我决定创建一个数据框来轻松启用绘图过程。
lst = fl.readlines()
lst_splt = [ s.replace('#','').split() for s in lst]
cp = pd.DataFrame.from_records(lst_splt[1:], columns=lst_splt[:1]).astype(float)
最后我尝试使用 seaborn 绘制它:
sns.lineplot(x='x',y='Cp', data=cp)
但正如我在问题开头所说的那样,出现了错误:
*** ValueError: If using all scalar values, you must pass an index
我可以做些什么来修复这个错误?
【问题讨论】:
-
您可以尝试将 index=[0] 添加到参数 DataFrame.from_records(data, index=[0]) 中吗?我无法复制您的场景,但以前对我有用。
-
您是否尝试检查 DataFrame 是否与您期望的一样?可以?您是否尝试检查(例如,通过阅读文档)Seaborn 是否希望以这种方式排列数据?当您尝试复制和粘贴
If using all scalar values, you must pass an indexinto a search engine 时发生了什么? -
您确定错误出现在
sns.lineplot上,而不是出现在外观不寻常的pd.DataFrame.from_records上。你能在数据框创建后打印出cp.head()吗? -
与
cp = pd.read_csv(flname,'r', sep='\s+',skiprows=(3), header=None, index=[0])错误*** TypeError: read_csv() got multiple values for argument 'sep'在读取cp 时仍然存在。我没有设法通过这个修改到达sns.lineplot