gpt4 book ai didi

python - pandas df.plot.scatter 失败但 df.plot 生成绘图

转载 作者:行者123 更新时间:2023-12-01 06:32:11 24 4
gpt4 key购买 nike

我想从 pandas df 生成数据散点图,示例如下。 enter image description here我可以使用以下方法生成线图:

ax = df_stats.plot(x = 't', y = 't_TI_var_ws')
ax1 = ax.twinx()
df_stats.plot(x='t',y='t_TI_var_pwr',ax=ax1, color='g')

enter image description here

但是当我尝试使用 .scatter 绘制与散点图相同的数据时,我收到错误 KeyError: 't'

ax = df_stats.plot.scatter(x = 't', y = 't_TI_var_ws')
ax1 = ax.twinx()
df_stats.plot.scatter(x='t',y='t_TI_var_pwr',ax=ax1, color='g')

最佳答案

您的列似乎是时间戳。要使用分散,它必须是 float 。您可以使用以下方式绘制散点图:

ax = df_stats.plot(x = 't', y='t_TI_var_pwr',style='o')      

关于python - pandas df.plot.scatter 失败但 df.plot 生成绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59846049/

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