gpt4 book ai didi

python - 绘制数据框的散点图

转载 作者:太空宇宙 更新时间:2023-11-03 17:34:39 26 4
gpt4 key购买 nike

我有以下数据框:

    A                B         C    
0 0.691295 0.179792 0.062371
1 NaN 0.179915 0.102003
2 NaN 0.186998 0.102183
3 NaN 0.189350 0.102220
4 NaN 0.189637 0.103003

如何绘制散点图

  • x 是 0 到 1 之间的值

  • y 是列名称(即同一列中的所有值应具有相同的 y 值),

  • 每列值都有不同的颜色

最佳答案

IIUC,你可以这样做:

import pandas as pd

# Just some values.
df = pd.DataFrame({
'a': np.random.rand(5),
'b': np.random.rand(5),
'c': np.random.rand(5)})

# Now for the plots.

# Plot a values at 1.
plot(df.a, [1] * 5, '+');
# Plot b values at 2.
plot(df.b, [2] * 5, '+');
# Plot c values at 3.
plot(df.c, [3] * 5, '+');
# Ensure extreme points visible.
ylim(0, 4)
# Set the ticks to 'a', 'b', and 'c'.
yticks([1, 2, 3], ['a', 'b', 'c']);

这给出了:

enter image description here

关于python - 绘制数据框的散点图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31372097/

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