[Python Study Notes]堆叠柱状图绘制
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
>>文件: 堆叠直方图.py
>>作者: liu yang
>>邮箱: liuyang0001@outlook.com
>>博客: www.cnblogs.com/liu66blog ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #!/usr/bin/env python
# -*- coding: utf-8 -*- import matplotlib.pyplot as plt
import matplotlib
# 定义要使用的字体,防止出现中文乱码
font=matplotlib.font_manager.FontProperties(fname=r"C:\Windows\Fonts\Deng.ttf") # 双层直方图,上下结构 适用于一个柱状图全部高于另一组
def barsplot():
# 先生成一个画布
fig=plt.figure()
# 生成数据
x1=[x for x in range(1,9)]
y1=[n*2 for n in range(1,9)]
x2=[x for x in range(1,9)]
y2=[x**2 for x in x2]
# 开始画条形图2,先画数值大的,数值小的直接在原图覆盖
l2=plt.bar(x2,y2,color='b',width=0.4)
# 开始画条形图1
l1=plt.bar(x1,y1,color='g',width=0.4)
# 设置x标签
plt.xlabel(u'x轴',fontproperties=font)
# 设置y轴标签
plt.ylabel('y轴',fontproperties=font)
# 设置标题
plt.title(u'堆叠柱状图',fontproperties=font)
# 设置注解狂
plt.legend(handles = [l1, l2,], labels = ['去年', '今年'], loc = 'best',prop=font)
# 把确切数字显示出来
for x1,x2, y1, y2 in zip(x1,x2, y1, y2):
plt.text(x1 , y1, '%.0f' % y1, ha='center', va='bottom')
plt.text(x2 , y2, '%.0f' % y2, ha='center', va='bottom')
# 显示
plt.show() # 如果最为主模块运行
if __name__ == '__main__':
# 实例化
ba=barsplot()
[Python Study Notes]堆叠柱状图绘制的更多相关文章
- [Python Study Notes]水平柱状图绘制
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- [Python Study Notes]双层柱状图绘制
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- [Python Study Notes]气泡散点图绘制
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- [Python Study Notes]七彩散点图绘制
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- [Python Study Notes]折线图绘制
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- [Python Study Notes]饼状图绘制
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- [Python Study Notes]匿名函数
Python 使用 lambda 来创建匿名函数. lambda这个名称来自于LISP,而LISP则是从lambda calculus(一种符号逻辑形式)取这个名称的.在Python中,lambda作 ...
- [Python Study Notes]字符串处理技巧(持续更新)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- [Python Study Notes]with的使用
在 Python 2.5 中, with 关键字被加入.它将常用的 try ... except ... finally ... 模式很方便的被复用.看一个最经典的例子: with open('fil ...
随机推荐
- jedis中的一致性hash算法
[http://my.oschina.net/u/866190/blog/192286] jredis是redis的java客户端,通过sharde实现负载路由,一直很好奇jredis的sharde如 ...
- VS2010 + QT 5 +open inventor 环境配置
本科毕业设计做的是 随钻测量的井眼轨迹和测井曲线的三维显示 要求的环境是 QT + Open Inventor 在寒假开学前,打算将环境配置好,开学后再正式编码实现,可是....环境也 ...
- jsp:jstl标签之控制流程
下面将要讲的用于流程控制的标签,其中包括:if.choose.when 与 otherwise 等.接下来对这些标签逐一讲解. 这个标签的作用和 Java 程序中的 if 语句作用相同,用于判断条件语 ...
- 20个PHP面试题及答案
php学了那么久了,先来小试牛刀,看下这些PHP程序员面试题都会不会?初级题目1.问题:请用最简单的语言描述PHP是什么?答:PHP全称:Hypertext Preprocessor,是一种用来开发动 ...
- js杨辉三角
function Tree() { this.lines = [ [] ] } var pp = Tree.prototype pp.genNode = function(line, i) { , , ...
- Senior Manufacturing Technical Manager
Job Description As a Manufacturing Technical Manager, you will be responsible for bringing new produ ...
- 树莓派(Arduino)仿真软件 —— Fritzing
Fritzing 官网:Fritzing Fritzing 下载地址:Fritzing Download windows 下降 zip 文件解压后,免安装双击 exe 即可运行:
- CodeForces - 682E: Alyona and Triangles(旋转卡壳求最大三角形)
You are given n points with integer coordinates on the plane. Points are given in a way such that th ...
- python与mongodb
一.mongodb的原理介绍: 特点: 为了理解以上特点,我们从一个真实的场景出发,介绍mongodb的原理:参考视频:https://www.youtube.com/watch?v=4SxHNmk5 ...
- Communication System(动态规划)
个人心得:百度推荐的简单DP题,自己做了下发现真得水,看了题解发现他们的思维真得比我好太多太多, 这是一段漫长的锻炼路呀. 关于这道题,我最开始用DP的思路,找子状态,发现自己根本就不会找DP状态数组 ...