在图形上注释
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(-10,11,1)
plt.plot(x,x*x)
plt.annotate('this is the bottom', xy=(0, 1), xytext = (0, 20), arrowprops = dict(facecolor = 'r', frac = 0.2, headwidth = 10, width = 10))
在图形上标注纯文字
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(-10,11,1)
y = x*x
plt.plot(x,y)
plt.text(-2,40,'function: y = x*x')
plt.text(-2,40,r"$\alpha$")
plt.text(-2,40,'function: y = x*x', family = 'serif', size = 20, color= 'r', style = 'italic', weight = 1000, bbox = dict(facecolor = 'r', alpha = 0.2))
区域填充
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 5*np.pi, 1000)
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)
fig = pli.figure()
ax = plt.gca()
ax.plot(x, y1, x,y2, color = 'black')
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)
生成图形
import matplotlib.pyplot as plt
import numpy as np
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)
ellipse = mpatches.Ellipse(xy4, 0.4,0.2, color = 'y')
ax.add_patch(circle)
ax.add_patch(rect)
ax.add_patch(polygon)
ax.add_patch(ellipse)
plt.axis('equal')
plt.grid()
极坐标
import numpy as np
import matplotlib as plt
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)