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

标签 python pandas python-2.7 dataframe plot

我想从 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/

相关文章:

python - 选择第一个元素之后的第二个元素

python - 还是关于python文件操作

python - 记忆化:用硬币找零

Python - 根据在组中出现多次来定义变量

python - Pandas 在日期时间多索引框架上滚动

python - 格式化字符串的问题 - Python 2.7.3

python - 将 Json 文件 URL 导入 pandas 数据框

python - 使用 update() 向字典添加值

python - 在脚本中导入 numpy 语句

python - 如何比较 2 个列表,其中字符串与备用列表中的元素匹配