Matplotlib学习(12)--注释和文字

1.注释
代码如下

import matplotlib.pyplot as plt
import numpy as np
x = np.arange(-10,11,1)
y = x*x
plt.plot(x,y)
# 添加注释  xy 箭头坐标,xytext 注释文字坐标,arrowprops:frac 箭头占比例,headwidth 箭头宽度,width 箭身宽度
plt.annotate("thi is the bottom",xy=(0,1),xytext=(0,20),arrowprops=dict(facecolor='r',frac=0.2,headwidth=30,width=10))

运行结果
在这里插入图片描述
2.文字(只画纯文字,不画箭头)
代码如下

import matplotlib.pyplot as plt
import numpy as np
x = np.arange(-10,11,1)
y = x*x
plt.plot(x,y)
# family 设置字体,size 设置文字大小,style设置是否斜体,weight设置粗细
plt.text(-2,40,"fucntion:y=x*x",family="serif",size=12,color='r',style='italic',weight='black')
plt.text(-2,20,"fucntion:y=x*x",family="fantacy",size=12,color='g',style='oblique',weight='light')

运行结果
在这里插入图片描述
3.txt公式
matplotlib自带mathtext引擎,不需安装Txt系统
代码如下

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

ax = fig.add_subplot(111)
ax.set_xlim([1,7])
ax.set_ylim([1,5])
# 也可以用plt.text()
ax.text(2,4,r"$ \alpha_i \beta_j \pi \lambda \omega $",size=16)
ax.text(4,4,r"$ \sin(0)=\cos(\frac{\pi}{2}) $",size=16)
ax.text(2,2,r"$ \lim_{x \rightarrow y} \frac{1}{x^3} $",size=16)
ax.text(4,2,r"$ \sqrt[4]{x}=\sqrt{y} $",size=16)

运行结果
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值