matplotlib 画图函数(二)

import numpy as np
import matplotlib.pyplot as mp

mp.figure(facecolor='lightgray')
mp.title('fill', fontsize=18)
x = np.linspace(0, 10, 1000)
sinx = np.sin(x)
cosx = np.cos(x / 2) / 2
mp.grid(linestyle=':', color='r')#'-' solid line style 实线样式 '--' dashed line style 虚线样式 '-.' dash-dot line style 虚点线样式 ':' dotted line style 冒号样式
mp.plot(x, sinx, label=r'$y=sin(x)$')
mp.plot(x, cosx, color='orangered',
        label=r'$y=\frac{1}{2}cos(\frac{x}{2})$')
mp.legend()
mp.fill_between(x, sinx, cosx, sinx > cosx, color='dodgerblue', alpha=0.3)
mp.fill_between(x, sinx, cosx, sinx < cosx,
                color='orangered', alpha=0.3)
mp.legend()
mp.show()
xiaoming = np.array([57, 55, 58, 49, 52, 43, 59])
xiaohong = np.array([95, 90, 97, 83, 87, 80, 99])
mp.figure('Bar', facecolor='lightgray')
mp.title('Bar Chart', fontsize=18)
mp.grid(linestyle=':')
x = np.arange(xiaoming.size)
mp.bar(x - 0.2, xiaoming, 0.4, color='limegreen',
       label='xiaoming', align='center')
mp.bar(x + 0.2, xiaohong, 0.4, color='orangered',
       label='xiaohong', align='center')
mp.xticks(x, ['yuwen', 'shuxue', 'yingyu', 'wuli', 'huaxue', 'zhengzhi', 'lishi'])
mp.show()
values = [57, 55, 58, 49, 52, 43, 59]
spaces = [0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.05]
labels = ['yuwen', 'shuxue', 'yingyu', 'wuli', 'huaxue', 'zhengzhi', 'lishi']
colors = ['dodgerblue', 'orangered', 'limegreen', 'violet', 'gold', 'blue', 'red']
mp.figure('Pie Chart')
mp.pie(values, spaces, labels, colors, '%.1f%%', shadow=True)
mp.legend()
mp.show()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值