Pandas DataFrame plot 绘制饼状图和柱状图
【摘要】 环境信息ModelArtsNotebook - Multi-Engine 2.0 (python3)JupyterLab - Notebook - Conda-python3pandas 1.1.5 Pandas DataFrame plot 绘制饼状图和柱状图import pandas as pdimport numpy as npdf = pd.DataFrame(np.random...
环境信息
- ModelArts
- Notebook - Multi-Engine 2.0 (python3)
- JupyterLab - Notebook - Conda-python3
- pandas 1.1.5
- JupyterLab - Notebook - Conda-python3
- Notebook - Multi-Engine 2.0 (python3)
Pandas DataFrame plot 绘制饼状图和柱状图
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(100,size=(3,1)),columns=['num'])
df
# 饼图
# 显示的小数位数 autopct='%.3f%%'
df.plot(kind="pie",subplots=True,autopct='%.3f%%')
# 柱状图
df.plot(kind="bar")
help
# 选取前半部分,主要看一下 kind ,即可以绘制的图表类型
help(df.plot)
Help on PlotAccessor in module pandas.plotting._core object:
class PlotAccessor(pandas.core.base.PandasObject)
| Make plots of Series or DataFrame.
|
| Uses the backend specified by the
| option ``plotting.backend``. By default, matplotlib is used.
|
| Parameters
| ----------
| data : Series or DataFrame
| The object for which the method is called.
| x : label or position, default None
| Only used if data is a DataFrame.
| y : label, position or list of label, positions, default None
| Allows plotting of one column versus another. Only used if data is a
| DataFrame.
| kind : str
| The kind of plot to produce:
|
| - 'line' : line plot (default)
| - 'bar' : vertical bar plot
| - 'barh' : horizontal bar plot
| - 'hist' : histogram
| - 'box' : boxplot
| - 'kde' : Kernel Density Estimation plot
| - 'density' : same as 'kde'
| - 'area' : area plot
| - 'pie' : pie plot
| - 'scatter' : scatter plot
| - 'hexbin' : hexbin plot.
......
备注
- 欢迎各位同学一起来交流学习心得^_^
- 在线课程、沙箱实验、认证、论坛和直播,其中包含了许多优质的内容,推荐了解与学习。
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)