matplotlib.pyplot.text( x, y, s, fontdict=None, withdash=False, **kwargs)
x, y : 文字位置座標html
s : 文字內容api
fontdict : 字典, 可選, 文字屬性函數
withdash : boolean, optional, default: False字體
Textspa
class matplotlib.font_manager.FontProperties( family=None, style=None, variant=None, weight=None, stretch=None, size=None, fname=None, _init=None)
family: 字體優先級列表‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, ‘monospace’code
style: 字體風格 ‘normal’, ‘italic’ , ‘oblique’.orm
variant: ‘normal’ or ‘small-caps’.htm
stretch: 0-1000數字或者 ‘ultra-condensed’, ‘extra-condensed’, ‘condensed’, ‘semi-condensed’, ‘normal’, ‘semi-expanded’, ‘expanded’, ‘extra-expanded’, ‘ultra-expanded’中的一個utf-8
weight: 字體粗細,0-1000之間數字或者 ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’中的一個ci
size: 字體大小,‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’ 或者一個整數
#-*-coding:utf-8-*- from __future__ import print_function from matplotlib.font_manager import FontProperties import matplotlib.pyplot as plt # text = "TEXT" ax = plt.subplot(331) ax.axis([-2,2,-2,2]) ax.text(0,0, 'TEXT') ax.set_title("(0,0)") ax = plt.subplot(332) ax.axis([-2,2,-2,2]) ax.text(0,0, 'TEXT',withdash=True) ax.set_title("withdash=True") ax = plt.subplot(333) ax.axis([-2,2,-2,2]) ax.text(0,0,'TEXT',ha="center",size=20,bbox=dict(boxstyle="circle", fc="b", ec="r")) ax.set_title("bbox=dict(boxstyle=circle, fc=b, ec=r)") ax = plt.subplot(334) ax.axis([-2,2,-2,2]) # ax.text(0,0,'TEXT',size=20, ha='left', rotation=15, wrap=True,style='oblique',va="top") ax.text(0,0,'TEXT',size=20, ha='left', rotation=15,style='oblique',va="top") ax.set_title("size=20, ha=left, rotation=15,style=oblique,va=top") ax = plt.subplot(335) ax.axis([-2,2,-2,2]) ax.text(0,0,'TEXT',size=15, rotation=30.,ha="center", va="center",bbox=dict(boxstyle="round",ec=(1., 0.5, 0.5),fc=(1., 0.8, 0.8))) ax.set_title("srotation=30") ax = plt.subplot(336) ax.axis([-2,2,-2,2]) ax.text(0,0,'TEXT',size=15, rotation=-30.,ha="right", va="top",bbox=dict(boxstyle="square",ec=(1., 0.5, 0.5),fc=(1., 0.8, 0.8))) ax.set_title("rotation=-30") ax = plt.subplot(337) ax.axis([-2,2,-2,2]) fp = FontProperties() fp.set_size('xx-large') fp.set_family('serif') fp.set_variant('small-caps') fp.set_weight('bold') fp.set_style('italic') ax.text(0,0,'TEXT',fontproperties=fp) ax.set_title("fontproperties=fp") ax = plt.subplot(338) ax.axis([-2,2,-2,2]) ax.text(0,0,'TEXT',size=15,zorder=2) ax.text(0,0.2,'TEXT',size=15,color="red",zorder=1,alpha=0.3) ax.set_title(u"zorder對比,和html中的z-index類似") ax = plt.subplot(339) ax.axis([-2,2,-2,2]) font = {'family': 'serif', 'color': 'darkred', 'weight': 'normal', 'size': 16, } ax.text(0,0,'TEXT',size=15,fontdict=font) ax.set_title("fontdict") plt.gcf().set_size_inches(12,10) plt.savefig("text.png") plt.show()
大概的樣子就像是下面的樣子的: