pandas plot

plot 绘图

import pandas as pd
excel_name = '5.1-5.9数据.xlsx'
df = pd.read_excel(excel_name, index_col=2, parse_dates=True)  # 以第二行为索引

ax = df.plot()
fig = ax.get_figure()  # 快速的绘图
ax.savefig('888.png')

# ax = df.plot().get_figure()  # 快速的绘图
# ax.savefig('888.png')

以哪列绘图

ax = df['age'].plot().get_figure()
ax.savefig('888.png')

定义 xy 轴

ax = df.plot.scatter(x='age', y='height', alpha=0.5).get_figure()
ax.savefig('888.png')

绘图类型

ax = df['age'].plot.kde().get_figure()
ax.savefig('888.png')

‘line’ : line plot (default)#折线图
‘bar’ : vertical bar plot#条形图
‘barh’ : horizontal bar plot#横向条形图
‘hist’ : histogram#柱状图
‘Box’ : Boxplot#箱线图
‘kde’ : Kernel Density Estimation plot#Kernel 的密度估计图,主要对柱状图添加Kernel 概率密度线
‘density’ : same as ‘kde’
‘area’ : area plot#不了解此图
‘pie’ : pie plot#饼图
‘scatter’ : scatter plot#散点图  需要传入columns方向的索引

matplotlib

import pandas as pd
import matplotlib.pyplot as plt
excel_name = '5.1-5.9数据.xlsx'
df = pd.read_excel(excel_name, index_col=2, parse_dates=True)
fig, axs = plt.subplots(figsize=(12, 4))  # 创建一个空matplotlib图和轴
df.plot.area(ax=axs)  # 利用 pandas 把区域策划准备图/轴
axs.set_ylabel('age')  # matplotlib定制
fig.savefig('444.png')


相关文章

转载:一文讲述Pandas库的数据读取、数据获取、数据拼接、数...
Pandas是一个开源的第三方Python库,从Numpy和Matplotlib的基...
整体流程登录天池在线编程环境导入pandas和xrld操作EXCEL文件...
 一、numpy小结             二、pandas2.1为...
1、时间偏移DateOffset对象DateOffset类似于时间差Timedelta...
1、pandas内置样式空值高亮highlight_null最大最小值高亮背景...