# encoding: utf-8
"""
Author: 沙振宇
CreateTime: 2019-4-29
UpdateTime: 2019-12-12
Info: matplotlib 使用示例 —— 柱形图
"""
import numpy as np
import matplotlib.pyplot as plt
#柱状图
A1 = [0.88,0.81,0.85]
A2 = [0.89,0.86,0.84]
A3 = [0.88,0.83,0.89]
A4 = [0.86,0.86,0.88]
A5 = [0.90,0.83,0.83]
x = np.arange(3) #总共有几组,就设置成几,我们这里有三组,所以设置为3
total_width, n = 0.6, 5 # n有多少个类型
width = total_width / n
x = x - (total_width - width) / 2
plt.bar(x, A1, color = "r",width=width,label='a1 ')
plt.bar(x + width, A2, color = "y",width=width,label='a2')
plt.bar(x + 2 * width, A3 , color = "c",width=width,label='a3')
plt.bar(x + 3 * width, A4 , color = "g",width=width,label='a4')
plt.bar(x + 4 * width, A5 , color = "b",width=width,label='a5')
plt.xlabel("横轴的名字")
plt.ylabel("纵轴的名字")
plt.legend(loc = "best")
plt.xticks([0,1,2],['左边','中间','右边'])
plt.ylim((0.8, 0.95))
my_y_ticks = np.arange(0.8, 0.95, 0.02)
plt.yticks(my_y_ticks)
plt.rcParams['font.sans-serif']=['SimHei'] # 中文
plt.show()
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Matplotlib_Python_教程.zip (10个子文件)
Matplotlib_Python_教程
饼图.png 25KB
三维散点图.png 160KB
折线图.png 30KB
Demo_Line_Chart.py 612B
Demo_3D_Scatter_Plot.py 746B
Demo_Bar_Chart.py 1KB
柱形图.png 14KB
散点图.png 18KB
Demo_Pie_Chart.py 884B
Demo_Scatter_Plot.py 388B
共 10 条
- 1
资源评论
倾城一少
- 粉丝: 661
- 资源: 62
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功