'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
>>文件: 水平直方图.py
>>作者: liu yang
>>邮箱: liuyang0001@outlook.com
>>博客: www.cnblogs.com/liu66blog ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #!/usr/bin/env python
# -*- coding: utf-8 -*- import sys, os
import matplotlib
import matplotlib.pyplot as plt
# 定义要使用的字体,防止出现中文乱码
font=matplotlib.font_manager.FontProperties(fname=r"C:\Windows\Fonts\Deng.ttf") # Horizontal histogram 水平直方图
def horizontal_histogram():
# 先生成一个画布
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]
# 画水平直方图
l2=plt.barh(x2,y2,color='b')
l1=plt.barh(x1,y1,color='g')
# 设置
plt.title("水平直方图",fontproperties=font)
# 设置x,y轴标签
plt.xlabel('数量',fontproperties=font)
plt.ylabel('产品',fontproperties=font)
# 设置刻度
plt.xticks([x for x in range(0,80,4)])
plt.yticks([y for y in range(0,9,1)])
# 设置注解狂图示
plt.legend(handles = [l1, l2,], labels = ['去年', '今年'], loc = 'best',prop=font)
for x1,x2, y1, y2 in zip(x1,x2, y1, y2):
# 添加文本时添加偏移量使其显示更加美观
plt.text(y1+1.5 , x1-0.25, '%.0f' % y1, ha='center', va='bottom')
plt.text(y2+1.5 , x2-0.25, '%.0f' % y2, ha='center', va='bottom')
# 显示
plt.show()
if __name__ == '__main__':
histogram = horizontal_histogram()

[Python Study Notes]水平柱状图绘制的更多相关文章

  1. [Python Study Notes]堆叠柱状图绘制

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  2. [Python Study Notes]双层柱状图绘制

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  3. [Python Study Notes]气泡散点图绘制

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  4. [Python Study Notes]七彩散点图绘制

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  5. [Python Study Notes]折线图绘制

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  6. [Python Study Notes]饼状图绘制

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  7. [Python Study Notes]匿名函数

    Python 使用 lambda 来创建匿名函数. lambda这个名称来自于LISP,而LISP则是从lambda calculus(一种符号逻辑形式)取这个名称的.在Python中,lambda作 ...

  8. [Python Study Notes]字符串处理技巧(持续更新)

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  9. [Python Study Notes]with的使用

    在 Python 2.5 中, with 关键字被加入.它将常用的 try ... except ... finally ... 模式很方便的被复用.看一个最经典的例子: with open('fil ...

随机推荐

  1. demo(幸福大转盘)总结

    百度推广首页demo 在<head>与</head>之间加入代码 <link rel="shortcut icon" href="favic ...

  2. docker安装---CentOS_7

    操作系统要求 要安装Docker,您需要64位版本的CentOS 7.步骤:   卸载旧版本 Docker的旧版本被称为docker或docker-engine . 如果这些已安装,请卸载它们以及关联 ...

  3. Codeforces Round #435 (Div. 2) c+d

    C:给n和k要求,找出n个不同的数,使得亦或起来等于k 可以先预处理从1到1e5,找亦或起来等于(11111111111111111)(二进制)的所有对数,然后四个一起亦或就是0了,再和k亦或 可以看 ...

  4. Xcode 查找 TODO 清单

    在 Xcode 中按 Shift+Command+F,显示在项目中查找窗口,选择按正则表达式查找(Find > Regular Expression): TODO:  //\s*\bTODO\s ...

  5. android:descendantFocusability用法简析(转)

        开发中很常见的一个问题,项目中的listview不仅仅是简单的文字,常常需要自己定义listview,自己的Adapter去继承BaseAdapter,在adapter中按照需求进行编写,问题 ...

  6. wiredtiger引擎性能——比levelDB更牛叉!

    WE'VE JOINED MONGODB!   We're proud to announce that MongoDB has acquired WiredTiger, and we've join ...

  7. BEC translation exercise 7

    在挑选时我们完全出自疏忽而漏过了这篇短文.In making the selection we passed this short piece by quite inadvertently. we l ...

  8. Codeforces Round #276 (Div. 2)A. Factory(数论)

    这道题可以暴力的一直按要求的方法去做,做1000000次还不能整除m就认为永远不能整除m了(m不超过100000,循环1000000次比较安全了已经).这种方法可以AC. 下面深入的分析一下到底循环多 ...

  9. 20179203 《Linux内核原理与分析》第十二周作业

    Return-to-libc 攻击实验 一.实验描述 缓冲区溢出的常用攻击方法是用 shellcode 的地址来覆盖漏洞程序的返回地址,使得漏洞程序去执行存放在栈中 shellcode.为了阻止这种类 ...

  10. hadoop碰到的 一个问题

    在里面添加/usr/local/hadoop/etc/hadoop/log4j.properties log4j.logger.org.apache.hadoop.util.NativeCodeLoa ...