惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
Vulnerabilities – Threatpost
Cloudbric
Cloudbric
G
GRAHAM CLULEY
S
Securelist
Schneier on Security
Schneier on Security
Help Net Security
Help Net Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
Spread Privacy
Spread Privacy
P
Privacy International News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
T
Tailwind CSS Blog
博客园_首页
有赞技术团队
有赞技术团队
Simon Willison's Weblog
Simon Willison's Weblog
Stack Overflow Blog
Stack Overflow Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
T
Tor Project blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Attack and Defense Labs
Attack and Defense Labs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
O
OpenAI News
J
Java Code Geeks
T
Tenable Blog
K
Kaspersky official blog
AWS News Blog
AWS News Blog
S
Security @ Cisco Blogs
The GitHub Blog
The GitHub Blog
T
Threatpost
月光博客
月光博客
H
Heimdal Security Blog
Security Latest
Security Latest
The Hacker News
The Hacker News
Y
Y Combinator Blog
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
C
Cisco Blogs
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
C
CERT Recently Published Vulnerability Notes
D
Docker
Google Online Security Blog
Google Online Security Blog
D
DataBreaches.Net
V
Visual Studio Blog
H
Help Net Security

博客园 - 玛瑙河

Python中用MacFSEvents模块监视MacOS文件系统改变一例 修改gnome-shell扩展“Applications Menu”的菜单区域宽度。 VirtualBox 4.3.18 启动虚拟机时显示不能加载 R3模块并退出故障解决一例 自定义IPython Qt Console 窗口大小、字体、颜色 Windows Server 2012 R2 两个奇葩问题的解决 cherokee +php fastcgi 出现 No input file specified 故障一例 ubuntu下从源码编译安装cherokee liftweb整合ckfinder进行文件上传与管理 命令行下多线程下载工具 Axel 2.4 for Windows 正确设置H2数据库的Collation解决中文排序问题 解决MASM编程对话框中文问题 清除U盘子目录变成1K大小的快捷方式病毒的脚本 Scala 脚本的 pound bang 魔术 Google URL Shorter HTML中常用的特殊字符实体编码(Character entity references in HTML 4) - 玛瑙河 MrBayes v3.2 for windows 并行版下载及 checkpoint 功能介绍 强制垃圾回收解决.NET Office互操作中文件锁未能释放的问题 童言无忌之小瑈与甲虫 MrBayes v3.1.2 for windows 并行版下载
用matplotlib绘制带误差的条形图及中英文字体设置
玛瑙河 · 2017-05-24 · via 博客园 - 玛瑙河
  1 #!/usr/bin/env python3
  2 
  3 ## 以下是一个带误差条的条形图的例子,演示了误差条形图的绘制及中英文字体设置
  4 import numpy as np
  5 import matplotlib as mpl
  6 import matplotlib.pyplot as plt
  7 from matplotlib.font_manager import FontProperties as FP
  8 
  9 # %matplotlib inline
 10 # %config InlineBackend.figure_format = 'svg'
 11 
 12 mpl.rcParams['text.usetex'] = False
 13 mpl.rcParams['figure.figsize'] = (7.40, 5.55) # unit: inch
 14 mpl.rcParams['figure.frameon'] = False
 15 
 16 ## 中文设置
 17 # matplotlib默认不支持ttc,所以可以将ttc转换ttf先。
 18 # 将Windows字体 simsun.ttc上传到 https://transfonter.org/ttc-unpack 在线转换成TTF,
 19 # 得到simsun.ttf和nsimsun.ttf,将两个ttf文件放到PYTHON安装目录的
 20 # Lib\site-packages\matplotlib\mpl-data\fonts\ttf 子目录下。
 21 # 删除字体缓存以便重新生成字体缓存:$HOME/.matplotlib/fontList.py3k.cache
 22 
 23 
 24 # 全局中文设置
 25 mpl.rcParams['font.family'] = 'sans-serif'
 26 mpl.rcParams['font.sans-serif'] = 'NSimSun,Times New Roman'
 27 
 28 # 局部中文:设置分别为中文和英文设置两个FontProperties,以便局部切换中英文字体
 29 cfp = FP('NSimSun', size=12)
 30 efp = FP('Times New Roman', size=12)
 31 
 32 fig,ax = plt.subplots()
 33 
 34 xticklabels = ('G1', 'G2', 'G3')
 35 ylabel = 'd'
 36 
 37 male_means = (9, 10, 9)
 38 male_std = (4.66, 3.52, 5.32)
 39 female_means = (12, 14, 12)
 40 female_std = (6.96, 5.46, 3.61)
 41 title = 'XX实验结果'
 42 
 43 N=3 
 44 ind = np.arange(N)  # the x locations for the groups
 45 width = 0.35  # the width of the bars
 46 with plt.style.context(('ggplot')):
 47     rects1 = ax.bar(
 48         ind - 0.02, female_means, width, color='darkgrey', yerr=female_std)
 49     rects2 = ax.bar(
 50         ind + 0.02 + width,
 51         male_means,
 52         width,
 53         color='lightgrey',
 54         yerr=male_std)
 55 
 56     ax.set_ylabel('d', fontproperties=efp, rotation=0)
 57     # 在label、title中可用参数'fontproperties' 指定字体
 58 
 59     ax.yaxis.set_label_coords(-0.05, 0.95)
 60     ax.set_title(title)
 61     ax.set_xticks(ind + width / 2)
 62 
 63     ax.set_xticklabels(xticklabels, fontproperties=efp)
 64 
 65     ax.legend((rects1[0], rects2[0]), ('处理A', '处理B'), prop=cfp, framealpha=0)
 66     # 在legend中可用参数'prop'指定字体,注意不是'fontproperties'
 67 
 68     def autolabel(rects, yerr):
 69         """
 70         Attach a text label above each bar displaying its height
 71         """
 72         for i in range(0, N):
 73             rect = rects[i]
 74             height = rect.get_height()
 75             ax.text(
 76                 rect.get_x() + rect.get_width() / 2.,
 77                 1.05 * height,
 78                 '%0.2f' % yerr[i],
 79                 ha='left',
 80                 va='bottom',
 81                 family='Georgia',
 82                 fontsize=9)
 83             #在text函数中可用family和fontsize指定字体
 84 
 85     autolabel(rects1, female_means)
 86     autolabel(rects2, male_means)
 87 
 88 ax.text(
 89     1,
 90    20,
 91     'Hello World',
 92     color = 'b',
 93     ha='left',
 94     va='bottom',
 95     fontproperties=efp)
 96 # 在text函数中也可用fontproperties指定字体
 97 
 98 fig.tight_layout()
 99 fig.savefig('filename.svg', format='svg')
100 # 保存为矢量图svg格式,如需插入word,可以用inkscape软件将其转换成emf格式