简体   繁体   English

seaborn.catplot 在更改 x 和 y 的值时出现 ValueError

[英]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而不是timestampservo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Seaborn Catplot 仅更改其中 1 行的 X 和 Y 标签 - Seaborn Catplot only changing the X and Y labels on 1 of the rows seaborn.catplot() 色调无法正常工作 - seaborn.catplot() hue is not working properly 获得在 seaborn.catplot 中计算的平均值的标准误差 - Obtain standard error of mean as computed in seaborn.catplot 在 seaborn 中使用 catplot 时更改 x-labels 和宽度 - Changing x-labels and width while using catplot in seaborn 收到“ValueError:Series 的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。” 创建 seaborn 猫图时 - Receiving "ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()." when creating seaborn catplot robotframework ValueError: 参数 'arg' 的值 'xy' (x) 无法转换为 x - robotframework ValueError: Argument 'arg' got value 'x.y' (x) that cannot be converted to x Seaborn catplot 通过更改色调导致错误 - Seaborn catplot results in error by changing hue Seaborn catplot 中是否有参数显示零值条? - Is there a parameter in Seaborn catplot to display bars with zero value? ValueError: s 必须是标量,或者与 seaborn 可视化中的 x 和 y 大小相同 - ValueError: s must be a scalar, or the same size as x and y in seaborn visualization 如何用seaborn绘制一个破碎的y轴猫图? - How to draw a broken y-axis catplot graphes with seaborn?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM