我正在尝试散点图以下数据框:
mydf = pd.DataFrame({'x':[1,2,3,4,5,6,7,8,9],
'y':[9,8,7,6,5,4,3,2,1],
'z':np.random.randint(0,9, 9)},
index=["12:00", "1:00", "2:00", "3:00", "4:00",
"5:00", "6:00", "7:00", "8:00"])
x y z
12:00 1 9 1
1:00 2 8 1
2:00 3 7 7
3:00 4 6 7
4:00 5 5 4
5:00 6 4 2
6:00 7 3 2
7:00 8 2 8
8:00 9 1 8
我希望将时间“12:00、1:00、...”视为 x 轴,将 x,y,z
列视为 y 轴。
当我尝试通过 mydf.plot(kind="scatter")
使用 pandas 绘图时,出现错误 ValueError: scatter requires and x and y column
。我是否必须将我的数据框分解为适当的参数?我真正想做的是用 seaborn 绘制这个散点图。
最佳答案
刚跑完
mydf.plot(style=".")
对我来说很好:
关于python - 如何获得数据框的简单散点图(最好使用 seaborn),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29279293/