# Day15

1336-陈同学

, ,

## 一、在图中进行注释

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(-10,11,1)

y = x*x

plt.plot(x,y)

plt.annotate("this is the bottom",xy=(0,1),xytext=(0,20),arrowprops=dict(facecolor="r",frac=0.2,headwidth=10,width=5))

plt.show()

## 二、文字

family参数是字体类型（官网可找的），size是字体大小，c是颜色，style可以设置斜体，weight可以设置加粗，bbox为设置给文字加框。

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(-10,11,1)
y = x*x

plt.plot(x,y)
plt.text(-4,40,"function:y=x*x",family='serif',size=20,c="r",style="italic",weight="black")
plt.text(-4,20,"function:y=x*x",family="fantasy",size=20,c="g",style="oblique",weight="light",bbox=dict(facecolor='r',alpha=0.2))
plt.show()

## 三、公式

import matplotlib.pyplot as plt

fig = plt.figure()

ax.set_xlim([1,7])
ax.set_ylim([1,5])

ax.text(2,4,r"$/alpha_i /beta_j /pi /lambda /omega$",size=25)

ax.text(4,4,r"$/sin(0)=/cos(/frac{/pi}{2})$",size=25)

ax.text(2,2,r"$/lim_{x /rightarrow y} /frac{1}{x^3}$",size=25)

ax.text(4,2,r"$/sqrt[4]{x}=/sqrt{y}$",size=25)
plt.show()

## 四、区域填充

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,5*np.pi,100)
y1 = np.sin(x)
y2 = np.sin(2*x)

# plt.plot(x,y1)
# plt.plot(x,y2)

# plt.fill(x,y1,'b',alpha=0.3)
# plt.fill(x,y2,"r",alpha=0.3)

fig = plt.figure()
ax = plt.gca()

ax.plot(x,y1,color="red")
ax.plot(x,y2,color="blue")
ax.fill_between(x,y1,y2,where=y1>y2,facecolor="yellow",interpolate=True)
ax.fill_between(x,y1,y2,where=y1<y2,facecolor="green",interpolate=True)
plt.show()

## 五、形状绘制

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

fig,ax = plt.subplots()
xy1 = np.array([0.2,0.2])
xy2 = np.array([0.2,0.8])
xy3 = np.array([0.8,0.2])
xy4 = np.array([0.8,0.8])
circle = mpatches.Circle(xy1,0.1)

rect = mpatches.Rectangle(xy2,0.2,0.1,color='r')

polygon = mpatches.RegularPolygon(xy3,5,0.1,color="g")

ellipse = mpatches.Ellipse(xy4,0.4,0.2,color="y")

plt.axis('equal')
plt.grid()

plt.show()

## 六、绘制极坐标

r = np.arange(1,6,1)
theta = [0,np.pi/2,np.pi,3*np.pi/2,2*np.pi]

ax = plt.subplot(111,projection="polar")

ax.plot(theta,r,color="r",linewidth=3)
ax.grid(True)
plt.show()

## 七、绘制函数的积分图

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

def fun(x):
return -(x-2)*(x-8)+40

a=2
b=9

x = np.linspace(0,10)

y = fun(x)

fig , ax = plt.subplots()

plt.plot(x,y,"r",linewidth=2)
ax.set_xticks([a,b])
ax.set_yticks([])

ax.set_xticklabels([r"$a$","$b$"])

ix = np.linspace(a,b)
iy = fun(ix)

ixy =zip(ix,iy)

verts = [(a,0)]+list(ixy)+[(b,0)]

ploy = mpatches.Polygon(verts,facecolor="0.9",edgecolor='0.5')
x_math  = (a+b)*0.5*0.5
y_math = 35

plt.text(x_math,y_math,r"$/int_a^b (-(x-2)*(x-8)+40)dx$",fontsize=15)
# plt.ylim(ymin=30)

plt.figtext(0.97,0.05,"$x$")
plt.figtext(0.01,0.95,"$y$")

plt.show()

Vieu3.3主题

Q Q 登 录