Matplotlib 中文用户指南 4.3 文本属性及布局
文本属性及布局
原文:Text properties and layout
译者:飞龙
协议:CC BY-NC-SA 4.0
matplotlib.text.Text
实例有各种属性,可以通过关键字参数配置文本命令(例如,title()
,xlabel()
和text()
)。
属性 | 值类型 |
---|---|
alpha | 浮点 |
backgroundcolor | 任何 matplotlib 颜色 |
bbox | rectangle prop dict plus key ‘pad’ which is a pad in points |
clip_box |
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 plt
import matplotlib.patches as patches# build a rectangle in axes coords
left, width = .25, .5
bottom, height = .25, .5
right = left + width
top = 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 right
p = 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()
Matplotlib 中文用户指南 4.3 文本属性及布局相关推荐
- Matplotlib 中文用户指南 4.1 文本介绍
引言 原文:Text introduction 译者:飞龙 协议:CC BY-NC-SA 4.0 matplotlib 具有优秀的文本支持,包括数学表达式,光栅和向量输出的 truetype 支持,任 ...
- Matplotlib 中文用户指南 3.1 pyplot 教程
pyplot 教程 原文:Pyplot tutorial 译者:飞龙 协议:CC BY-NC-SA 4.0 matplotlib.pyplot是一个命令风格函数的集合,使matplotlib的机制更像 ...
- Matplotlib 中文用户指南 4.5 标注
标注 原文:Annotation 译者:飞龙 协议:CC BY-NC-SA 4.0 基本标注 使用text()会将文本放置在轴域的任意位置. 文本的一个常见用例是标注绘图的某些特征,而annotate ...
- Matplotlib 中文用户指南 5.1 指定颜色
指定颜色 原文:Specifying Colors 译者:飞龙 协议:CC BY-NC-SA 4.0 在 matplotlib 的几乎所有地方,用户都可以指定颜色,它可以以如下形式提供: RGB 或者 ...
- Matplotlib 中文用户指南 4.7 使用 LaTeX 渲染文本
使用 LaTeX 渲染文本 原文:Text rendering With LaTeX 译者:飞龙 协议:CC BY-NC-SA 4.0 Matplotlib 可以选择使用 LaTeX 来管理所有文本布 ...
- Matplotlib 中文用户指南 4.2 基本的文本命令
基本的文本命令 原文:Basic text commands 译者:飞龙 协议:CC BY-NC-SA 4.0 text 在Axes的任意位置添加文本. 命令式:matplotlib.pyplot.t ...
- Matplotlib 中文用户指南 3.6 图例指南
图例指南 原文:Legend guide 译者:飞龙 协议:CC BY-NC-SA 4.0 此图例指南是legend()中可用文档的扩展 - 请在继续阅读本指南之前确保你熟悉该文档(见篇尾)的内容. ...
- Matplotlib 中文用户指南 4.4 默认字体
默认字体 原文:Text properties and layout 译者:飞龙 协议:CC BY-NC-SA 4.0 基本的默认字体由一系列rcParams参数控制: rcParam 用法 'fon ...
- Matplotlib 中文用户指南 1 简介
简介 原文:Introduction 译者:飞龙 协议:CC BY-NC-SA 4.0 Matplotlib 是一个用于在 Python 中绘制数组的 2D 图形库.虽然它起源于模仿 MATLAB®[ ...
最新文章
- 视频插值--Video Frame Interpolation via Adaptive Separable Convolution
- 物联网激荡MEMS传感器浪潮
- Mac下使用Homebrew 安装MySQL
- 清华团队率先抵达摩尔定律最后节点,0.34nm栅长晶体管研究登Nature,打破斯坦福纪录...
- .top域名应注意什么
- linux lvm 调整分区大小,linux调整lvm分区大小(/home分区过大,/root分区过小)
- Nacos源码心跳异常检测
- javaSE各阶段练习题--数据类型运算符
- tf调不到keras怎么 回事_拼多多刷单关键词搜不到是怎么回事?如何解决?
- 前端学习(1737):前端调试值测试窗口的切换
- python全套学习方法_python学习方法总结(内附python全套学习资料)
- [gkk传智]static与多态及向下向上转型,及多态调用总结
- java程序设计基础篇_java程序设计基础篇 复习笔记 第一单元
- CNN 总结 模型归类
- IBM大中华区总架构师讲述话说程序员的职业生涯
- Chrome OS 下载及安装教程
- 审计工作存在的难点和问题_基层审计工作中存在的问题及建议
- ZigBee的应用场景
- 解决win10 phptoshop #fff纯白不是这样的白 显示器高级的问题
- 校招|我的秋招记录——(自然语言处理-面经+感悟)
热门文章
- 【蓝桥杯单片机】红外接收及NEC红外通信协议
- 【STM32】HAL库 STM32CubeMX教程十五---FMC-SDRAM(一)
- mysql 两行的差异_MySQL两行之间的日期差异
- 腾讯企业邮箱服务器地址imap端口号,腾讯企业邮箱如何设置IMAP、POP3/SMTP及其SSL加密方式...
- 调试 高通_高通平台调整通话音量
- php 小程序回调,微信小程序Promise简化回调实例分享
- 死锁的充分必要条件、死锁预防、死锁避免、死锁检测和解除
- Java面试之什么是GCRoots,能做什么?
- centos/redhat破解账号密码
- JavaScript 删除某个数组中指定的对象