1.title设置图像标题

(1)title常用参数
fontsize设置字体大小,默认12,可选参数 ['xx-small', 'x-small', 'small', 'medium', 'large','x-large', 'xx-large']
fontweight设置字体粗细,可选参数 ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
fontstyle设置字体类型,可选参数[ 'normal' | 'italic' | 'oblique' ],italic斜体,oblique倾斜
verticalalignment设置水平对齐方式 ,可选参数 : 'center' , 'top' , 'bottom' ,'baseline' 
horizontalalignment设置垂直对齐方式,可选参数:left,right,center
rotation(旋转角度)可选参数为:vertical,horizontal 也可以为数字
alpha透明度,参数值0至1之间
backgroundcolor标题背景颜色
bbox给标题增加外框 ,常用参数如下:
  • boxstyle方框外形
  • facecolor(简写fc)背景颜色
  • edgecolor(简写ec)边框线条颜色
  • edgewidth边框线条大小

(2)title例子:

plt.title('Interesting Graph',fontsize='large',fontweight='bold') 设置字体大小与格式
plt.title('Interesting Graph',color='blue') 设置字体颜色
plt.title('Interesting Graph',loc ='left') 设置字体位置
plt.title('Interesting Graph',verticalalignment='bottom') 设置垂直对齐方式
plt.title('Interesting Graph',rotation=45) 设置字体旋转角度
plt.title('Interesting',bbox=dict(facecolor='g', edgecolor='blue', alpha=0.65 )) 标题边框

面向对象api例子:

  1.  
    import matplotlib.pyplot as plt
  2.  
    x=[1,2,3,4,5]
  3.  
    y=[3,6,7,9,2]
  4.  
     
  5.  
    fig,ax=plt.subplots(1,1)
  6.  
    ax.plot(x,y,label='trend')
  7.  
    ax.set_title('title test',fontsize=12,color='r')
  8.  
    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 设置注释文字偏移量

         | 参数 | 坐标系 | 
         | 'figure points' | 距离图形左下角的点数量 | 
         | 'figure pixels' | 距离图形左下角的像素数量 | 
         | 'figure fraction' | 0,0 是图形左下角,1,1 是右上角 | 
         | 'axes points' | 距离轴域左下角的点数量 | 
         | 'axes pixels' | 距离轴域左下角的像素数量 | 
         | 'axes fraction' | 0,0 是轴域左下角,1,1 是右上角 | 
         | 'data' | 使用轴域数据坐标系 |

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)案例

  1.  
    import matplotlib.pyplot as plt
  2.  
    import numpy as np
  3.  
    x = np.arange(0, 6)
  4.  
    y = x * x
  5.  
    plt.plot(x, y, marker='o')
  6.  
    for xy in zip(x, y):
  7.  
    plt.annotate("(%s,%s)" % xy, xy=xy, xytext=(-20, 10), textcoords='offset points')
  8.  
    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)案例

文字格式与位置:
  1.  
    import matplotlib.pyplot as plt
  2.  
    fig = plt.figure()
  3.  
    plt.axis([0, 10, 0, 10])
  4.  
    t = "This is a really long string that I'd rather have wrapped so that it"\
  5.  
    " doesn't go outside of the figure, but if it's long enough it will go"\
  6.  
    " off the top or bottom!"
  7.  
    plt.text(4, 1, t, ha='left', rotation=15, wrap=True)
  8.  
    plt.text(6, 5, t, ha='left', rotation=15, wrap=True)
  9.  
    plt.text(5, 5, t, ha='right', rotation=-15, wrap=True)
  10.  
    plt.text(5, 10, t, fontsize=18, style='oblique', ha='center',va='top',wrap=True)
  11.  
    plt.text(3, 4, t, family='serif', style='italic', ha='right', wrap=True)
  12.  
    plt.text(-1, 0, t, ha='left', rotation=-15, wrap=True)
  13.  
    plt.show()

 
花式文本框:
  1.  
    import matplotlib.pyplot as plt
  2.  
    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),))
  3.  
    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),))
  4.  
    plt.draw()
  5.  
    plt.show()

数学公式:

  1.  
    plt.title(r'$\alpha_i > \beta_i$', fontsize=20)
  2.  
    plt.text(1, -0.6, r'$\sum_{i=0}^\infty x_i$', fontsize=20)
  3.  
    plt.text(0.6, 0.6, r'$\mathcal{A}\mathrm{sin}(2 \omega t)$',fontsize=20)

matplotlib命令与格式:标题(title),标注(annotate),文字说明(text)的更多相关文章

  1. matplotlib命令与格式:参数配置文件与参数配置

    转自 https://my.oschina.net/swuly302/blog/94805 自定义matplotlib Created Saturday 08 December 2012 5.1 ma ...

  2. (三)Linux命令基本格式以及文件处理命令

    命令基本格式 (1)命令提示符 如下是命令行的命令提示符,以此为例,讲解含义. 其中: root 当前登录用户名 localhost 主机名 ~ 当前所在的目录(即家目录,用户登录的初始位置) # 超 ...

  3. 十条常用nmap命令行格式

    十条常用nmap命令行格式 ) 获取远程主机的系统类型及开放端口 nmap -sS -P0 -sV -O <target> 这里的 < target > 可以是单一 IP, 或 ...

  4. javascript 的Date 格式化, 模仿shell中date命令的格式

    原文:javascript 的Date 格式化, 模仿shell中date命令的格式 shell 中显示当前的日期 [root@localhost]$ date '+%Y-%m-%d %H:%M:%S ...

  5. Python生成PASCAL VOC格式的xml标注文件

    Python生成PASCAL VOC格式的xml标注文件 PASCAL VOC数据集的标注文件是xml格式的.对于py-faster-rcnn,通常以下示例的字段是合适的: <annotatio ...

  6. DOS中命令的格式

    ---------------siwuxie095 一.DOS中,命令使用格式的一般形式 用中文表达的形式为: [路径]  关键字  [盘符]  [路径]  文件名  [扩展名]  (参数)  [参数 ...

  7. 山寨今日头条的标题title效果

    山寨今日头条的标题title效果 效果: 源码: // // ViewController.m // 今日头条 // // Created by YouXianMing on 14/11/26. // ...

  8. 使用jquery修改标题$("title").html("标题")应注意的问题

    使用jquery修改标题$("title").html("标题")应注意的问题: 如果修改后的标题和原标题一致,jquery会跳过该操作,这种情况再从其他页面回 ...

  9. SEO页面标题Title的优化

    我在一个月前改过页面标题(Title),随后表现是:百度网页快照4天不更新,Google正常.而我仅仅是改了两个词组而已.在建博初期,修改Title的最频繁的时期,下面卢松松就我经历的修改Title过 ...

随机推荐

  1. C#文件运行类的VB.NET版本号

    主要差别在于事件处理要採用AddHandler和RemoveHandler,以及AddressOf三个keyword,其他基本一样. VB的操作稍微繁琐.但仍然能够实现.

  2. hdu 1024 Max Sum Plus Plus (子段和最大问题)

    Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  3. Solr基础教程之solrconfig.xml(三)

    前面介绍过schema.xml的一些配置信息,本章介绍solrconfig.xml的配置,以及怎样安装smartcn分词器和IK分词器,并介绍主要的查询语法. 1. solr配置solrconfig. ...

  4. Database returned no natively generated

    database returned no natively generated 分类:Hibernatehbm.xml中的配置如下: <id name="logId" typ ...

  5. python 数据描述字符串转整数

    q3 = int(float(q3.replace('万', '')) * 10000)

  6. poj 2104 K-th Number(主席树,详细有用)

    poj 2104 K-th Number(主席树) 主席树就是持久化的线段树,添加的时候,每更新了一个节点的线段树都被保存下来了. 查询区间[L,R]操作的时候,只需要用第R棵树减去第L-1棵树就是区 ...

  7. Bing Maps进阶系列六:使用Silverlight剪切(Clip)特性实现Bing Maps的迷你小地图

    Bing Maps进阶系列六:使用Silverlight剪切(Clip)特性实现Bing Maps的迷你小地图 Bing Maps Silverlight Control虽然为我们提供了简洁.方面的开 ...

  8. P2495 [SDOI2011]消耗战 虚树

    这是我做的第一道虚树题啊,赶脚不错.其实虚树也没什么奇怪的,就是每棵树给你一些点,让你多次查询,但是我不想每次都O(n),所以我们每次针对给的点建一棵虚树,只包含这些点和lca,然后在这棵虚树上进行树 ...

  9. 洛谷P2303 [SDOi2012]Longge的问题

    题目背景 SDOi2012 题目描述 Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). ...

  10. Makefile 实际用例分析(一) ------- 比较通用的一种架构

    这里不再说Makefile的基本知识,如果需要学习,那么请参考: 下载:makefile 中文手册 或者 点击打开链接 或者 跟我一起写Makefile( 陈皓 ) 这里说的是一般的实际的一个工程应该 ...