[英]seaborn.catplot got ValueError when changing the value for x and y
I'm writing a python script to plot how status fluctuate between s0 and s2 as time going on.我正在写一个 python 脚本到 plot 随着时间的推移,状态如何在 s0 和 s2 之间波动。 My input look like this:
我的输入看起来像这样:
timestamp|servo
0|s0
1|s0
2|s2
3|s0
4|s2
5|s0
6|s0
The way I wrote my input csv is like this:我写输入 csv 的方式是这样的:
headers = ['timestamp', 'servo']
with open(('/home/ray/proj/5th_output/asym/slave/test/' + str(testname) + '.csv'), 'w', newline='') as csvfile:
spamwriter = csv.DictWriter(csvfile, fieldnames=headers, delimiter='|')
spamwriter.writeheader()
for i in range(0, len(eachservo)):
row = {'timestamp': str(ts[i]), 'servo': eachservo[i]}
spamwriter.writerow(row)
The way I plot my csv input is like:我 plot 我的 csv 输入的方式是这样的:
for csvname in glob.glob(os.path.join(path, '*.csv')):
readcsv = pd.read_csv(csvname)
sns.set(style="ticks")
g = sns.catplot(x=timestamp, y=servo, data=readcsv)
The plot I got is correct in terms of the content, but the title of x and y is completely messed up:我拿到的plot,内容是正确的,但是x和y的标题完全乱了:
However, if I change sns.catplot(x=timestamp, y=servo, data=readcsv)
to sns.catplot(x='timestamp', y='servo', data=readcsv)
, it will report a valueError saying ValueError: Could not interpret input 'timestamp'
, so I'm stucking with using two lists as parameter for catplot.但是,如果我将
sns.catplot(x=timestamp, y=servo, data=readcsv)
更改为sns.catplot(x='timestamp', y='servo', data=readcsv)
,它将报告一个 valueError 说ValueError: Could not interpret input 'timestamp'
,所以我坚持使用两个列表作为 catplot 的参数。
What mistake am I making here?我在这里犯了什么错误? Is it the way I wrote csv causing this issue or I miss some catplot argument?
是我写 csv 的方式导致了这个问题,还是我错过了一些 catplot 参数?
EDIT:编辑:
I found where my problem is, it's because I use csv.DoctWriter to write a csv and then panda for reading it.我找到了我的问题所在,这是因为我使用 csv.DoctWriter 写了一个 csv 然后用 panda 读取它。 I solved it by replacing csv.DoctWriter with pandas
to_csv
.我通过将 csv.DoctWriter 替换为 pandas
to_csv
来解决它。
I found where my problem is, it's because I use csv.DoctWriter
to write a csv and then panda for reading it.我找到了我的问题所在,这是因为我使用
csv.DoctWriter
写了一个 csv 然后用 panda 读取它。 I solved it by replacing csv.DoctWriter
with pandas to_csv
.我通过将
csv.DoctWriter
替换为 pandas to_csv
来解决它。
By using csv.DoctWriter
with delimiterto = '|'
通过使用
csv.DoctWriter
with delimiterto = '|'
write and use pd.read_csv
, the column in the csv will be read as timestamp|servo
instead of timestamp
and servo
.写入并使用
pd.read_csv
, csv 中的列将被读取为timestamp|servo
而不是timestamp
和servo
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.