python_matplotlib DAY_22(1)注释,图例,填充

学习内容
matplotlib的注释操作
重点
1.注释plt.annotate

import numpy as np
import matplotlib.pyplot as plt

a = np.arange(-10, 10, 0.1)
b = a ** 2
plt.plot(a, b)
plt.annotate("this is bottom", xy=(0, 1), xytext=(-1.87, 20),
             arrowprops=dict(facecolor='b',
                             headwidth=15, width=10))
#标题的文本,点头所指的位置,文本的位置,arrowprops是更改指针的数据
plt.show()

在这里插入图片描述

2文本plt.text()

import numpy as np
import matplotlib.pyplot as plt

a = np.arange(-10, 10, 0.1)
b = a ** 2
plt.plot(a, b)
plt.annotate("this is bottom", xy=(0, 1), xytext=(-1.87, 20),
             arrowprops=dict(facecolor='b',
                             headwidth=15, width=10))
plt.text(-3.5,40,'function:y=x²',family='serif',size=20,color='r',
         style='italic',weight=20,
         bbox=dict(facecolor='r',alpha=0.2))
#坐标位置,显示内容,字体格式,字体大小,颜色,字体风格,字体类型,背景设置(颜色,透明度)
plt.show()

3.Tex公式(数学公式)

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.set_xlim([-5, 5])
ax.set_ylim([-3, 3])
ax.text(-4,2,r'$\alpha_i\beta_j\lambda\omega$',
        size=30,family='serif')
ax.text(-4,-2,r'$\sin(0)=\cos(\frac{\pi}{2})$',size=20,
        family='serif')
ax.text(0.5,2,r'$\lim_{x\rightarrow y}\frac{1}{x^3}$',size=20,
        family='serif')
ax.text(0.5,-2,r'$\sqrt[4]{x}=\sqrt{y}$',size=20,
        family='serif')
plt.show()

在这里插入图片描述

4.填充颜色fill,fill.between

import numpy as np
import matplotlib.pyplot as plt

a=np.arange(-np.pi,np.pi,0.01)
b1=np.sin(a)
b2=np.sin(2*a)
plt.fill(a,b1,'r',alpha=0.3)#填充
plt.fill(a,b2,'b',alpha=0.3)#填充
plt.show()

在这里插入图片描述

fill_between

import numpy as np
import matplotlib.pyplot as plt

a=np.arange(-np.pi,np.pi,0.01)
b1=np.sin(a)
b2=np.sin(2*a)
fig=plt.figure()
ax=fig.add_subplot(1,1,1)
ax.plot(a,b1,'r')
ax.plot(a,b2,'b')
ax.fill_between(a,b1,b2,where=b1>=b2,facecolor='y',interpolate=True)
ax.fill_between(a,b1,b2,where=b2>=b1,facecolor='G',interpolate=True)
plt.show()

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值