Pandas是非常常见的数据分析工具,我们一般都会处理好处理数据然后使用searbon或matplotlib来进行绘制。但在Pandas内部就已经集成了matplotlib,本文将展示Pandas内部的画图方法。
画图类型
在Pandas中内置的画图方法如下几类,基本上都是常见的画图方法。每种方法底层也是使用的matplotlib。
-
line: line plot (default) -
bar: vertical bar plot -
barh: horizontal bar plot -
hist: histogram -
box: boxplot -
density/kde: Density Estimation -
area: area plot -
pie: pie plot -
scatter: scatter plot -
hexbin: hexbin plot
在进行画图时我们有两种调用方法:
df = pd.DataFrame({
'sales': [3, 3, 3, 9, 10, 6],
'signups': [4, 5, 6, 10, 12, 13],
'visits': [20, 42, 28, 62, 81, 50],
}, index=pd.date_range(start='2018/01/01', end='2018/07/01', freq='M'))
# 方法1,这种方法是高层API,需要制定kind
df.plot(kind='area')
# 方法2,这种方法是底层API
df.plot.area()

面积图(area)
面积图直观地显示定量数据下面的区域面积,该函数包装了 matplotlib 的area函数。
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.area.html
# 默认为面积堆叠
df.plot(kind='area')

本文介绍了Pandas库中内置的10种画图方法,包括面积图、条形图、水平条形图、箱线图、密度图、六边形图、直方图、折线图、饼图和散点图。这些方法基于matplotlib实现,帮助用户直观展示数据分析结果。
最低0.47元/天 解锁文章
3万+

被折叠的 条评论
为什么被折叠?



