我想从 pandas df 生成数据散点图,示例如下。 我可以使用以下方法生成线图:
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')
但是当我尝试使用 .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/