gpt4 book ai didi

python - Matplotlib:多线图

转载 作者:行者123 更新时间:2023-11-30 22:00:48 26 4
gpt4 key购买 nike

我的数据框如下所示:

Bin           A      B      C   Proba-a%   Proba-b%   Proba-c%    gamma%
CPB%
0.100 20841 23195 24546 34.503457 27.103303 22.859837 0.100
0.200 2541 4187 5176 26.517913 13.944499 6.593338 0.200
0.300 2750 1823 1122 17.875550 8.215217 3.067253 0.300
0.400 999 829 448 14.736015 5.609856 1.659334 0.400
0.500 604 495 217 12.837838 4.054181 0.977373 0.500
0.600 436 348 116 11.467630 2.960495 0.612822 0.600
0.700 367 247 76 10.314268 2.184230 0.373979 0.700
0.800 305 186 35 9.355751 1.599673 0.263985 0.800
0.900 280 115 24 8.475801 1.238254 0.188561 0.900
1.000 200 102 18 7.847266 0.917691 0.131992 1.000

我想做的是在 x 轴上有“gamma%”和一个包含三行 A、B 和 C 的图表。我在某个地方看到你必须多次调用 plt,我尝试过:

plt.plot(x='gamma%', y='A', data=df_b)
plt.plot(x='gamma%', y='B',data=df_b)
plt.plot(x='gamma%', y='C',data=df_b)

但是我遇到了以下错误:

ValueError: Using arbitrary long args with data is not supported due to ambiguity of arguments.
Use multiple plotting calls instead.

有什么想法吗?谢谢!

最佳答案

其实你的方法很好,只是不明确说x='gamma%' 。相反,只需传递列名称,如 'gamma%'它应该可以工作

示例:

plt.plot('gamma%', 'A', data=df_b)

这里直接来自 documentation :

Plotting labelled data

There's a convenient way for plotting objects with labelled data (i.e. data that can be accessed by index obj['y']). Instead of giving the data in x and y, you can provide the object in the data parameter and just give the labels for x and y:

plot('xlabel', 'ylabel', data=obj)

关于python - Matplotlib:多线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54233996/

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