matplotlib命令与格式:标题(title),标注(annotate),文字说明(text)
1.title设置图像标题
- boxstyle方框外形
- facecolor(简写fc)背景颜色
- edgecolor(简写ec)边框线条颜色
- edgewidth边框线条大小
(2)title例子:
面向对象api例子:
- import matplotlib.pyplot as plt
- x=[1,2,3,4,5]
- y=[3,6,7,9,2]
- fig,ax=plt.subplots(1,1)
- ax.plot(x,y,label='trend')
- ax.set_title('title test',fontsize=12,color='r')
- plt.show()
2.annotate标注文字
(1)annotate语法说明 :annotate(s='str' ,xy=(x,y) ,xytext=(l1,l2) ,..)
s 为注释文本内容
xy 为被注释的坐标点
xytext 为注释文字的坐标位置
xycoords 参数如下:
- figure points points from the lower left of the figure 点在图左下方
- figure pixels pixels from the lower left of the figure 图左下角的像素
- figure fraction fraction of figure from lower left 左下角数字部分
- axes points points from lower left corner of axes 从左下角点的坐标
- axes pixels pixels from lower left corner of axes 从左下角的像素坐标
- axes fraction fraction of axes from lower left 左下角部分
- data use the coordinate system of the object being annotated(default) 使用的坐标系统被注释的对象(默认)
- polar(theta,r) if not native ‘data’ coordinates t
extcoords 设置注释文字偏移量
arrowprops #箭头参数,参数类型为字典dict
- width the width of the arrow in points 点箭头的宽度
- headwidth the width of the base of the arrow head in points 在点的箭头底座的宽度
- headlength the length of the arrow head in points 点箭头的长度
- shrink fraction of total length to ‘shrink’ from both ends 总长度为分数“缩水”从两端
- facecolor 箭头颜色
bbox给标题增加外框 ,常用参数如下:
- boxstyle方框外形
- facecolor(简写fc)背景颜色
- edgecolor(简写ec)边框线条颜色
- edgewidth边框线条大小
bbox=dict(boxstyle='round,pad=0.5', fc='yellow', ec='k',lw=1 ,alpha=0.5) #fc为facecolor,ec为edgecolor,lw为lineweight
(2)案例
- import matplotlib.pyplot as plt
- import numpy as np
- x = np.arange(0, 6)
- y = x * x
- plt.plot(x, y, marker='o')
- for xy in zip(x, y):
- plt.annotate("(%s,%s)" % xy, xy=xy, xytext=(-20, 10), textcoords='offset points')
- plt.show()
plt.annotate('local max', xy=(2, 1), xytext=(3, 1.5),arrowprops=dict(facecolor='black', shrink=0.05))
3.text设置文字说明
(1)text语法说明
text(x,y,string,fontsize=15,verticalalignment="top",horizontalalignment="right")
x,y:表示坐标值上的值
string:表示说明文字
fontsize:表示字体大小
verticalalignment:垂直对齐方式 ,参数:[ ‘center’ | ‘top’ | ‘bottom’ | ‘baseline’ ]
horizontalalignment:水平对齐方式 ,参数:[ ‘center’ | ‘right’ | ‘left’ ]
xycoords选择指定的坐标轴系统:
- figure points points from the lower left of the figure 点在图左下方
- figure pixels pixels from the lower left of the figure 图左下角的像素
- figure fraction fraction of figure from lower left 左下角数字部分
- axes points points from lower left corner of axes 从左下角点的坐标
- axes pixels pixels from lower left corner of axes 从左下角的像素坐标
- axes fraction fraction of axes from lower left 左下角部分
- data use the coordinate system of the object being annotated(default) 使用的坐标系统被注释的对象(默认)
- polar(theta,r) if not native ‘data’ coordinates t
arrowprops #箭头参数,参数类型为字典dict
- width the width of the arrow in points 点箭头的宽度
- headwidth the width of the base of the arrow head in points 在点的箭头底座的宽度
- headlength the length of the arrow head in points 点箭头的长度
- shrink fraction of total length to ‘shrink’ from both ends 总长度为分数“缩水”从两端
- facecolor 箭头颜色
bbox给标题增加外框 ,常用参数如下:
- boxstyle方框外形
- facecolor(简写fc)背景颜色
- edgecolor(简写ec)边框线条颜色
- edgewidth边框线条大小
bbox=dict(boxstyle='round,pad=0.5', fc='yellow', ec='k',lw=1 ,alpha=0.5) #fc为facecolor,ec为edgecolor,lw为lineweight
(2)案例
- import matplotlib.pyplot as plt
- fig = plt.figure()
- plt.axis([0, 10, 0, 10])
- t = "This is a really long string that I'd rather have wrapped so that it"\
- " doesn't go outside of the figure, but if it's long enough it will go"\
- " off the top or bottom!"
- plt.text(4, 1, t, ha='left', rotation=15, wrap=True)
- plt.text(6, 5, t, ha='left', rotation=15, wrap=True)
- plt.text(5, 5, t, ha='right', rotation=-15, wrap=True)
- plt.text(5, 10, t, fontsize=18, style='oblique', ha='center',va='top',wrap=True)
- plt.text(3, 4, t, family='serif', style='italic', ha='right', wrap=True)
- plt.text(-1, 0, t, ha='left', rotation=-15, wrap=True)
- plt.show()
- import matplotlib.pyplot as plt
- plt.text(0.6, 0.5, "test", size=50, rotation=30.,ha="center", va="center",bbox=dict(boxstyle="round",ec=(1., 0.5, 0.5),fc=(1., 0.8, 0.8),))
- plt.text(0.5, 0.4, "test", size=50, rotation=-30.,ha="right", va="top",bbox=dict(boxstyle="square",ec=(1., 0.5, 0.5),fc=(1., 0.8, 0.8),))
- plt.draw()
- plt.show()
数学公式:
- plt.title(r'$\alpha_i > \beta_i$', fontsize=20)
- plt.text(1, -0.6, r'$\sum_{i=0}^\infty x_i$', fontsize=20)
- plt.text(0.6, 0.6, r'$\mathcal{A}\mathrm{sin}(2 \omega t)$',fontsize=20)
matplotlib命令与格式:标题(title),标注(annotate),文字说明(text)的更多相关文章
- matplotlib命令与格式:参数配置文件与参数配置
转自 https://my.oschina.net/swuly302/blog/94805 自定义matplotlib Created Saturday 08 December 2012 5.1 ma ...
- (三)Linux命令基本格式以及文件处理命令
命令基本格式 (1)命令提示符 如下是命令行的命令提示符,以此为例,讲解含义. 其中: root 当前登录用户名 localhost 主机名 ~ 当前所在的目录(即家目录,用户登录的初始位置) # 超 ...
- 十条常用nmap命令行格式
十条常用nmap命令行格式 ) 获取远程主机的系统类型及开放端口 nmap -sS -P0 -sV -O <target> 这里的 < target > 可以是单一 IP, 或 ...
- javascript 的Date 格式化, 模仿shell中date命令的格式
原文:javascript 的Date 格式化, 模仿shell中date命令的格式 shell 中显示当前的日期 [root@localhost]$ date '+%Y-%m-%d %H:%M:%S ...
- Python生成PASCAL VOC格式的xml标注文件
Python生成PASCAL VOC格式的xml标注文件 PASCAL VOC数据集的标注文件是xml格式的.对于py-faster-rcnn,通常以下示例的字段是合适的: <annotatio ...
- DOS中命令的格式
---------------siwuxie095 一.DOS中,命令使用格式的一般形式 用中文表达的形式为: [路径] 关键字 [盘符] [路径] 文件名 [扩展名] (参数) [参数 ...
- 山寨今日头条的标题title效果
山寨今日头条的标题title效果 效果: 源码: // // ViewController.m // 今日头条 // // Created by YouXianMing on 14/11/26. // ...
- 使用jquery修改标题$("title").html("标题")应注意的问题
使用jquery修改标题$("title").html("标题")应注意的问题: 如果修改后的标题和原标题一致,jquery会跳过该操作,这种情况再从其他页面回 ...
- SEO页面标题Title的优化
我在一个月前改过页面标题(Title),随后表现是:百度网页快照4天不更新,Google正常.而我仅仅是改了两个词组而已.在建博初期,修改Title的最频繁的时期,下面卢松松就我经历的修改Title过 ...
随机推荐
- 将一个对象相同的属性(不区分大小写)赋值给一个新对象 DataTable的一个简单的扩展
将一个对象相同的属性(不区分大小写)赋值给一个新对象 1 public static T Mapper<S, T>(S source) 2 { 3 T t = Activator.Cr ...
- Android CardView使用和导入出错问题
Android CardView使用和导入出错问题 第一部分:导入Android CardView出错的问题. Android CardView是Android在support.v7包里面的一个vie ...
- Cant't call setState(or forceUpdate) on an unmount component. 报错的可能性原因
react 小白编程 遇到了如下错误 调试了很久没找到到底为啥 后来发现,是因为多次将组件挂在到根节点的原因导致的 使用路由之后,只需要使用 ReactDOM.render()方式将最外层的路由挂在到 ...
- HDU 5289 Assignment (二分+区间最值)
[题目链接]click here~~ [题目大意]: 给出一个数列,问当中存在多少连续子序列,子序列的最大值-最小值<k [思路]:枚举数列左端点.然后二分枚举右端点,用ST算法求区间最值.(或 ...
- EF TMD
TMD 几个月前,本着学习的心态,首次在项目中应用EF.因为这里老是赶.赶.赶,当时只是匆匆而就,浅尝辄止,搞到现在对EF一知半解,每次在新项目使用,都担惊受怕,大费周折,不知道什么时候,在什么地方就 ...
- 2017iOS开发最新的打包测试步骤(亲测)
最近也是忙着修改项目,今天把最近遇到的问题和知识给大家分享一下. 有时候我们需要将我们的项目发给测试组进行bug测试,这时候我们就需要把自己的项目打包,生成一个二维码或者链接的形式,给测试组,接下来就 ...
- hdu 6119 小小粉丝度度熊(尺取)
小小粉丝度度熊 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- 洛谷 P4149 [ IOI 2011 ] Race —— 点分治
题目:https://www.luogu.org/problemnew/show/P4149 仍然是点分治: 不过因为是取 min ,所以不能用容斥,那么子树之间就必须分开算,记录桶时注意这个: 每次 ...
- npm 与 package.json 快速入门教程
npm 与 package.json 快速入门教程 2017年08月02日 19:16:20 阅读数:33887 npm 是前端开发广泛使用的包管理工具,之前使用 Weex 时看了阮一峰前辈的文章了解 ...
- php 时间戳和时间的转换
PHP的时间戳与具体时间转化 三个内置函数: time() //获取UNIX系统时间戳 mktime(hour,minute,second,month,day,year) //将指定时间转化为时间戳 ...