数据分析~DataFrame画图

版权声明: https://blog.csdn.net/zbrj12345/article/details/81196837

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

%matplotlib notebook

# 设置绘图样式
plt.style.use('seaborn-colorblind')

np.random.seed(100)
df = pd.DataFrame({'A': np.random.randn(365).cumsum(0),
                  'B': np.random.randn(365).cumsum(0) + 20,
                  'C': np.random.randn(365).cumsum(0) - 20},
                 index=pd.date_range('2017/1/1', periods=365))
df.head(5)

#绘制

df.plot()

#绘制散点图

df.plot('A', 'B', kind='scatter')

# 颜色(c)和大小(s)有'B'列的数据决定
ax = df.plot('A', 'C', kind='scatter',
        c='B', s=df['B'], colormap='viridis')

# 设置坐标为相同比例
ax.set_aspect('equal')

#绘制盒形图

df.plot(kind='box')

#绘制直方图

df.plot(kind='hist', alpha=0.7)

#绘制拟合图

df.plot(kind='kde')

猜你喜欢

转载自blog.csdn.net/zbrj12345/article/details/81196837