[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 ...
随机推荐
- http://www.cnblogs.com/jscode/archive/2012/09/03/2669299.html
http://www.cnblogs.com/jscode/archive/2012/09/03/2669299.html
- Jquery Ajax模版
$.ajax({ type: "GET", url: "test.json", data: {username:'tt', content:'tt'}, dat ...
- 配置web项目出的各种error (安装sql2008错误,网站连接数据库error错误等等)
一个破error:40 错误搞出了很多莫名其妙的为问题,搞了5天,最后重装系统加上重新配置终于好了. 1. 关于SQL 2008 安装错误 安装之前必须安装VS2008 SP1 安装到最后提示 试 ...
- Mssql 跨域查询
有数据库test1和数据库test2.其中test1中有表 table1.table2:test2 中有表 table1.三个表的字段都为为:id.xingming.shijian.shuliang. ...
- eclispe中使用 maven build启动maven项目和打包项目
1.右键项目2.点击run as按钮 3.点击run configurations 4.配置如下: =============================加油加油加油加油加油加油========= ...
- hdu 5237 Base64(模拟)
Base64 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- Project://Meeting_Room
models from django.db import models from django.contrib.auth.models import AbstractUser class UserIn ...
- linux中使用opdir_readdir读取目录中的信息
#include <dirent.h>#include <stdio.h>#include <stdlib.h> int main(int argc, char * ...
- [转]Cache-Control max-age=0
Cache-Control max-age=0 Cache-Control no-cache — 强制每次请求直接发送给源服务器,而不经过本地缓存版本的校验.这对于需要确认认证应用很有用(可以和 ...
- Nexus安装以及2,3比较
解压缩之后, 进入nexus-3.6.2-01/bin文件夹中,执行: ./nexus start 如果使用root将会得到一个告警:Detected execution as "root& ...