首页 > 解决方案 > pandas plot(kind='line') 创建散点图

问题描述

我正在尝试pandas Series用一条线绘制 a 。这些线产生所示的输出和散点图。

import pandas as pd
print(pd.__version__)
...
print(type(sam))
print(sam)
sam.plot(kind='line');

0.25.3
<class 'pandas.core.series.Series'>
3300    0.87
3301    0.87
3302    0.87
3303    0.87
3304    0.87
Name: A, dtype: float64

<<SCATTER PLOT>>

我无法通过任何方式创建线图Series.plot

正确的做法是什么?

PS:我可以想出一些变通方法,比如创建新的np数组、列表等。但我想这应该可以马上工作。

PS2:我在 PortableApps 的 Chrome 下使用 Jupyter Lab。奇怪的是,在实验室的一个选项卡中(很少有东西),上面的线产生了一个线图,在另一个选项卡(sklearn加载)中,它产生了一个散点图。我将进一步实验。

标签: pythonpandasplot

解决方案


你可以试试:

sam = pd.Series([.87,.87,.87,.87,.87], index=range(3300, 3305))

系列:

3300    0.87
3301    0.87
3302    0.87
3303    0.87
3304    0.87
dtype: float64

线图:

sam.plot()

在此处输入图像描述

sam.plot(kind='line')呈现相同的输出。


推荐阅读