等待下一个秋

  • Spark
  • Flink
  • Hive
  • 数据仓库
  • ClickHouse
  • 收徒弟
  • Java
    • Spring
    • Mybatis
    • SpringBoot
    • 面试题
  • Python
    • Python基础
    • 爬虫
    • Numpy
    • matplotlib
    • Flask
  • 技术杂谈
    • Linux知识
    • Docker
    • Git教程
    • Redis教程
    • mysql
    • 前端
    • R语言
    • 机器学习
  • 关于我
  • 其它
    • 副业挣钱
    • 资料下载
    • 资料文档
专注于Hadoop/Spark/Flink/Hive/数据仓库等
关注公众号:大数据技术派,获取更多学习资料。
  1. 首页
  2. Python
  3. matplotlib
  4. 正文

Matplotlib 文本属性及布局

2020年11月11日 8670点热度 0人点赞 0条评论

文本属性及布局

原文: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 [ 点的尺寸 相对尺寸,例如 ['smaller', 'x-large' ]
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 + height

fig = 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()

标签: Python
最后更新:2022年7月19日

等待下一个秋

待我代码写成,便娶你为妻!专注于Hadoop/Spark/Flink/Hive/数据仓库等,关注公众号:大数据技术派,获取更多学习资料。

打赏 点赞
< 上一篇
下一篇 >

等待下一个秋

待我代码写成,便娶你为妻!专注于Hadoop/Spark/Flink/Hive/数据仓库等,关注公众号:大数据技术派,获取更多学习资料。

搜一搜
微信
最新 热点 随机
最新 热点 随机
ClickHouse 自定义分区键 ClickHouse数据副本引擎 ClickHouse ReplacingMergeTree引擎 ClickHouse MergeTree引擎 clickhouse简介 Flink SQL管理平台flink-streaming-platform-web安装搭建
那些年,我们听过的经典歌曲 个人品牌,越久越赚钱 大数据SQL中的Join谓词下推,真的那么难懂? 黑客与画家 3.不能说的话 SpringBoot连接Hive异常 Matplotlib 使用 GridSpec 自定义子图位置
标签聚合
Hive 挣钱 Flink 书籍 Redis Python 数据仓库 mysql 大数据 R语言 算法 Java
文章归档
  • 2022年12月
  • 2022年11月
  • 2022年9月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2021年1月
  • 2020年12月
  • 2020年11月
  • 2020年10月
  • 2020年9月
  • 2020年8月
  • 2020年7月
  • 2020年5月
  • 2020年4月
  • 2020年1月
  • 2019年9月
  • 2019年8月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年4月
  • 2019年3月
  • 2019年1月
  • 2018年12月
  • 2017年5月

©2022 ikeguang.com. 保留所有权利。

鄂ICP备2020019097号-1

鄂公网安备 42032202000160号