我是靠谱客的博主 美满发箍,这篇文章主要介绍python数据科学包---matplotlib(3),现在分享给大家,希望可以做个参考。

注释

主要用到的是plt.annotate()

import matplotlib.pyplot as plt
import numpy as np
x=np.arange(-10,11)
y=x**2
plt.plot(x,y)
plt.annotate('This is the bottom',xy=(0,1),xytext=(0,20),
arrowprops=dict(facecolor='g',headlength=10,headwidth=20,
width=10))
plt.show()

在这里插入图片描述
xy : (float, float)
The point (x,y) to annotate.

xytext : (float, float), optional
The position (x,y) to place the text at. If None, defaults to xy.

arrowprops : dict, optional
The properties used to draw a FancyArrowPatch arrow between the positions xy and xytext.

If arrowprops does not contain the key ‘arrowstyle’ the allowed keys are:
Key Description
width The width of the arrow in points
headwidth The width of the base of the arrow head in points
headlength The length of the arrow head in points
shrink Fraction of total length to shrink from both ends
? Any key to matplotlib.patches.FancyArrowPatch

详细用法:
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.annotate.html?highlight=annotate#matplotlib.pyplot.annotate

文字

plt.text()

import matplotlib.pyplot as plt
import numpy as np
x=np.arange(-10,11)
y=x**2
plt.plot(x,y)
plt.text(-2,40,'function:y=x*x')
plt.show()

在这里插入图片描述
详细:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.text.html?highlight=text#examples-using-matplotlib-pyplot-text

Tex公式

即编辑数学公式

如何画出数学公式,通过text公式,matplotlib自带mathtext,不需要安装text系统
绘制数据公式的方式, 作 为 开 始 和 结 束 符 中 间 包 含 数 学 公 式 , 如 " 作为开始和结束符中间包含数学公式,如" "y=x+z$",在绘图时会自动识别数学公式字符串,并解析成所对应的公式
mathtext文档:https://matplotlib.org/api/mathtext_api.html、
编写数学表达式的文档:https://matplotlib.org/tutorials/text/mathtext.html
在这里插入图片描述
在这里插入图片描述

最后

以上就是美满发箍最近收集整理的关于python数据科学包---matplotlib(3)的全部内容,更多相关python数据科学包---matplotlib(3)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部