Matplotlib 中文用户指南 4.3 文本属性及布局
来源:互联网 发布:模仿艺人语音软件 编辑:程序博客网 时间:2024/06/06 10:52
文本属性及布局
原文:Text properties and layout
译者:飞龙
协议:CC BY-NC-SA 4.0
matplotlib.text.Text
实例有各种属性,可以通过关键字参数配置文本命令(例如,title()
,xlabel()
和text()
)。
matplotlib.transform.Bbox
实例 clip_on [True / False]
clip_path Path
,Transform
或Patch
实例 color 任何 matplotlib 颜色 family [ 'serif' / 'sans-serif' / 'cursive' / 'fantasy' / 'monospace' ]
fontproperties matplotlib.font_manager.FontProperties
实例 horizontalalignment or ha [ 'center' / 'right' / 'left' ]
label 任何字符串 linespacing 浮点 multialignment ['left' / 'right' / 'center' ]
name or fontname 字符串,例如 ['Sans' / 'Courier' / 'Helvetica' ...]
picker [None
/ 浮点 / 布尔值 / 可调用对象]` position (x,y)
rotation [ 角度制的角度 / ‘vertical’ / ‘horizontal’ size or fontsize [ 点的尺寸 style or fontstyle [ 'normal' / 'italic' / 'oblique']
text 字符串或任何可使用'%s'
打印的东西 transform matplotlib.transform
实例 variant [ 'normal' / 'small-caps' ]
verticalalignment or va [ 'center' / 'top' / 'bottom' / 'baseline' ]
visible [True / False]
weight or fontweight [ 'normal' / 'bold' / 'heavy' / 'light' / 'ultrabold' / 'ultralight']
x 浮点 y 浮点 zorder 任意数值你可以使用对齐参数horizontalalignment
,verticalalignment
和multialignment
来布置文本。 horizontalalignment
控制文本的x
位置参数表示文本边界框的左边,中间或右边。 verticalalignment
控制文本的y
位置参数表示文本边界框的底部,中心或顶部。 multialignment
,仅对于换行符分隔的字符串,控制不同的行是左,中还是右对齐。 这里是一个使用text()
命令显示各种对齐方式的例子。 在整个代码中使用transform = ax.transAxes
,表示坐标相对于轴边界框给出,其中0,0
是轴的左下角,1,1
是右上角。
import matplotlib.pyplot as pltimport matplotlib.patches as patches# build a rectangle in axes coordsleft, width = .25, .5bottom, height = .25, .5right = left + widthtop = bottom + heightfig = plt.figure()ax = fig.add_axes([0,0,1,1])# axes coordinates are 0,0 is bottom left and 1,1 is upper rightp = patches.Rectangle( (left, bottom), width, height, fill=False, transform=ax.transAxes, clip_on=False )ax.add_patch(p)ax.text(left, bottom, 'left top', horizontalalignment='left', verticalalignment='top', transform=ax.transAxes)ax.text(left, bottom, 'left bottom', horizontalalignment='left', verticalalignment='bottom', transform=ax.transAxes)ax.text(right, top, 'right bottom', horizontalalignment='right', verticalalignment='bottom', transform=ax.transAxes)ax.text(right, top, 'right top', horizontalalignment='right', verticalalignment='top', transform=ax.transAxes)ax.text(right, bottom, 'center top', horizontalalignment='center', verticalalignment='top', transform=ax.transAxes)ax.text(left, 0.5*(bottom+top), 'right center', horizontalalignment='right', verticalalignment='center', rotation='vertical', transform=ax.transAxes)ax.text(left, 0.5*(bottom+top), 'left center', horizontalalignment='left', verticalalignment='center', rotation='vertical', transform=ax.transAxes)ax.text(0.5*(left+right), 0.5*(bottom+top), 'middle', horizontalalignment='center', verticalalignment='center', fontsize=20, color='red', transform=ax.transAxes)ax.text(right, 0.5*(bottom+top), 'centered', horizontalalignment='center', verticalalignment='center', rotation='vertical', transform=ax.transAxes)ax.text(left, top, 'rotated\nwith newlines', horizontalalignment='center', verticalalignment='center', rotation=45, transform=ax.transAxes)ax.set_axis_off()plt.show()
0 0
- Matplotlib 中文用户指南 4.3 文本属性及布局
- Matplotlib 中文用户指南 4.1 文本介绍
- Matplotlib 中文用户指南 3.5 密致布局指南
- Matplotlib 中文用户指南 4.2 基本的文本命令
- Matplotlib 中文用户指南 4.7 使用 LaTeX 渲染文本
- 转载:Matplotlib 中文用户指南 3.5 密致布局指南
- Matplotlib 中文用户指南 7.3 事件处理及拾取
- Matplotlib 中文用户指南 1 简介
- Matplotlib 中文用户指南 2 安装
- Matplotlib 中文用户指南 4.5 标注
- Matplotlib 中文用户指南 6 自定义 matplotlib
- Matplotlib 中文用户指南 3.1 pyplot 教程
- Matplotlib 中文用户指南 3.2 图像教程
- Matplotlib 中文用户指南 3.5 艺术家教程
- Matplotlib 中文用户指南 3.6 图例指南
- Matplotlib 中文用户指南 3.7 变换教程
- Matplotlib 中文用户指南 3.8 路径教程
- Matplotlib 中文用户指南 3.9 路径效果指南
- 异常字节码
- Subsets
- Matplotlib 中文用户指南 4.1 文本介绍
- Matplotlib 中文用户指南 4.2 基本的文本命令
- Git
- Matplotlib 中文用户指南 4.3 文本属性及布局
- 九度OJ-1107-搬水果
- 《领域驱动设计》阅读笔记 第1章 消化知识
- Matplotlib 中文用户指南 4.4 默认字体
- Matplotlib 中文用户指南 4.5 标注
- Matplotlib 中文用户指南 4.6 编写数学表达式
- 【Unity】如何对公共INT类型数字快速设置
- LeetCode_492. Construct the Rectangle
- 2 - 7 - Gradient Descent For Linear Regression (10 min)