1 Star 0 Fork 0

朱康宝/CSDN

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
bar.py 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
朱康宝 提交于 2018-12-14 14:35 +08:00 . bar
# -*- coding: utf-8 -*-
"""
date: Fri Dec 14 14:20:45 2018
python: Anaconda 3.6.5
author: kanade
email: kanade@blisst.cn
"""
import numpy as np
import matplotlib.pyplot as mp
# 生成数据
apples = np.array([30, 25, 22, 36, 21, 29,
20, 24, 33, 19, 27, 15])
oranges = np.array([24, 33, 19, 27, 35, 20,
15, 27, 20, 32, 20, 22])
durian = np.array([115, 88, 66, 68, 102, 92,
44, 59, 105, 96, 98, 75])
# 创建图形窗口
mp.figure('Bar', facecolor='lightgray')
# 设置窗口标题
mp.title('Bar', fontsize=20)
# 设置坐标轴标签
mp.xlabel('Month', fontsize=14)
mp.ylabel('Price', fontsize=14)
# 设置刻度参数
mp.tick_params(labelsize=10)
# 设置网格线型
mp.grid(axis='y', linestyle=':')
# 设置垂直坐标范围
mp.ylim(-40, 120)
# 绘制条形图
x = np.arange(len(apples))
mp.bar(x, -apples, 0.4, color='dodgerblue',
label='Apple')
# 加0.4是为了不和Apple重合
mp.bar(x + 0.4,-oranges, 0.4, color='orangered',
label='Orange', alpha=0.75)
mp.bar(x + 0.2, durian, 0.6, color='turquoise',
label='Durian')
# 设置水平坐标刻度标签,加0.1只是为了好看
mp.xticks(x + 0.1, (
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'))
# 绘制图例
mp.legend()
# 显示图形
mp.show()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/kanadeblisst/CSDN.git
git@gitee.com:kanadeblisst/CSDN.git
kanadeblisst
CSDN
CSDN
master

搜索帮助