[Python Study Notes]水平柱状图绘制
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
>>文件: 水平直方图.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]水平柱状图绘制的更多相关文章
- [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 ...
随机推荐
- RtlWerpReportException failed with status code :-1073741823
在release下程序运行总是崩溃:debugView输出了这个崩溃信息, 1. 一开始是release看崩溃,各种二分法找崩溃点,太玄没找到: 2. 终于想到可以调试,我草,调试一下瞬间发现某个cl ...
- 03-dotnet core创建区域[Areas]及后台搭建
熟悉MVC的人都知道从MVC4开始引入了区域的机制,区域的创建可以协助你在架构较大的项目中,让独立性较高的部分功能作为一个单独的子MVC系统,降低网站与网站之间的耦合度,也可以通过area切割,让多个 ...
- Eclipse 快捷键大全(群里共享的,留下来以后兴许会用到)
Eclipse快捷键大全Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加) Ctrl+Alt+↑ 复制当前行到上一行 ...
- Django Cookie Session和自定义分页
Django中操作Cookie 获取Cookie request.COOKIES['key'] request.get_signed_cookie(key, default=RAISE_ERROR, ...
- static数据成员与const数据成员的定义与初始化
三种数据类型的初始化 1.static int a 的初始化 const int a 的初始化 static const int a的初始化 三种初始化方式 在类外初始化 在构造函数中通过初始化列表初 ...
- Python_单元测试工具nose
一.nose的API nose的API地址:http://pythontesting.net/framework/nose/nose-introduction/ 二.安装nose 先用easy_ins ...
- CodeForces - 651D:Image Preview (双指针&)
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed ...
- HihoCoder1465 重复旋律8(后缀自动机)
描述 小Hi平时的一大兴趣爱好就是演奏钢琴.我们知道一段音乐旋律可以被表示为一段数构成的数列. 小Hi发现旋律可以循环,每次把一段旋律里面最前面一个音换到最后面就成为了原旋律的“循环相似旋律”,还可以 ...
- Python Indentation
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of th ...
- LG2865 [USACO06NOV]路障Roadblocks
题意 Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends. ...