文章目录
- 注释
- 文字
- Tex公式
- 区域填充
- 极坐标
注释
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))
plt.show()
文字
import matplotlib.pyplot as plt
import numpy as np
x=np.arange(-10,11,1)
y=x*x
plt.plot(x,y)plt.text(0,40,'functio:y=x*x',family='serif',size=20,color='r',style='italic')
plt.show()
import matplotlib.pyplot as plt
import numpy as np
x=np.arange(-10,11,1)
y=x*x
plt.plot(x,y)plt.text(0,40,'functio:y=x*x',family='serif',size=20,color='r',style='italic',bbox=dict(facecolor='r',alpha=0.2))
plt.show()
Tex公式
import matplotlib.pyplot as plt
import numpy as np
fig=plt.figure()
ax=fig.add_subplot(111)
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.fill(x,y1,'b',alpha=0.3)
plt.fill(x,y2,'r',alpha=0.3)
plt.show()
极坐标
import matplotlib.pyplot as plt
import numpy as np
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 matplotlib.pyplot as plt
import numpy as np
r=np.empty(5)
r.fill(5)
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()