matplotlib.pyplot画图

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
fig,axes = plt.subplots(2,2,figsize=(15,5))
#fig, ax = plt.subplots(1,3,figsize=(15,7)),这样就会有1行3个15x7大小的子图。
s = pd.Series(np.random.randint(0,10,15),index = list('abcdefghijklmno'))
#series是一个一维数组,是基于NumPy的ndarray结构。Pandas会默然用0到n-1来作为series的index,
#但也可以自己指定index(可以把index理解为dict里面的key)
#>>> np.random.randint(0,10,15)
#array([6, 2, 6, 5, 3, 3, 4, 4, 4, 3, 5, 9, 9, 5, 4])
df = pd.DataFrame(np.random.rand(10,3),columns = ['A','B','C'])
'''>>> np.random.rand(10,3)
array([[0.94427522, 0.29448375, 0.49052377],
       [0.41811686, 0.83101541, 0.01829453],
       [0.39953993, 0.94077862, 0.77839269],
       [0.0789365 , 0.15288723, 0.98586775],
       [0.58071493, 0.31034999, 0.14891302],
       [0.71382913, 0.34232445, 0.22874753],
       [0.34945889, 0.61219549, 0.41150743],
       [0.31807239, 0.81031528, 0.44313329],
       [0.8816291 , 0.8268357 , 0.62558377],
       [0.13080003, 0.33875718, 0.35158171]])'''
s.plot(kind = 'bar',ax = axes[0,0]) #kind表示图表类型
df.plot(kind = 'bar',ax = axes[0,1])
df.plot.bar(ax = axes[1,0],stacked = True)   #stacked = True表示显示为堆叠样式
df.plot.barh(ax = axes[1,1])  #横向的柱状图
plt.show()

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值