Matplotlib使用文本(Text)

Matplotlib使用文本(Text) 首页 / Matplotlib入门教程 / Matplotlib使用文本(Text)

Matplotlib支持文本、数学表达式、栅格和矢量输出的 TrueType等,包括matplotlib.font_manager,它实现了一个跨平台,符合W3C的字体查找算法。

用户可以对文本属性(字体大小,字体粗细,文本位置和颜色等)进行控制,Matplotlib实现了大量的TeX数学符号和命令。

无涯教程网

以下命令列表用于在Pyplot界面中创建文本-

text 在轴的任意位置添加文本。
annotate 在轴的任意位置添加带有可选箭头的注释。
xlabel 在轴的x轴上添加标签。
ylabel 在轴的y轴上添加标签。
title 为轴添加标题。
figtext 在图形的任意位置添加文本。
suptitle 在图形上添加标题。

所有这些函数都创建并返回 matplotlib.text.Text(),以下脚本演示了上述功能的使用-

链接:https://www.learnfk.comhttps://www.learnfk.com/matplotlib/matplotlib-working-with-text.html

来源:LearnFk无涯教程网

import matplotlib.pyplot as plt
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.set_title('axes title')
ax.set_xlabel('xlabel')
ax.set_ylabel('ylabel')
ax.text(3, 8, 'boxed italics text in data coords', style='italic', 
bbox = {'facecolor': 'red'})
ax.text(2, 6, r'an equation: $E=mc^2$', fontsize = 15)
ax.text(4, 0.05, 'colored text in axes coords',
verticalalignment = 'bottom', color = 'green', fontsize = 15)
ax.plot([2], [1], 'o')
ax.annotate('annotate', xy = (2, 1), xytext = (3, 4),
arrowprops = dict(facecolor = 'black', shrink = 0.05))
ax.axis([0, 10, 0, 10])
plt.show()

上面的代码行将生成以下输出-

Working With Text

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

教程推荐

结构思考力 · 透过结构看思考 -〔李忠秋〕

AI大模型之美 -〔徐文浩〕

快手 · 音视频技术入门课 -〔刘歧〕

说透低代码 -〔陈旭〕

Redis源码剖析与实战 -〔蒋德钧〕

容器实战高手课 -〔李程远〕

Linux实战技能100讲 -〔尹会生〕

深入浅出计算机组成原理 -〔徐文浩〕

持续交付36讲 -〔王潇俊〕

好记忆不如烂笔头。留下您的足迹吧 :)