数据生成:
import numpy as np
import matplotlib.pyplot as plt func = np.poly1d(np.array([,,,]))
func1 = func.deriv(m=) # 求一阶导数
func2 = func.deriv(m=) # 求二阶导数 x = np.linspace(-,,)
y = func(x)
y1 = func1(x)
y2 = func2(x)
'''正常绘图''' plt.plot(x,y,'ro',x,y1,'g--')
plt.xlabel('x')
plt.ylabel('y')
plt.show()
'''添加子图''' plt.subplot()
plt.plot(x,y,c='r',linestyle='-')
plt.title('Polynomial') plt.subplot()
plt.plot(x,y1,c='b',linestyle='',marker='^')
# plt.plot(x,y1,'b^')
plt.title('First Derivative') plt.subplot()
plt.plot(x,y2,c='g',linestyle='',marker='o')
plt.title('Second Derivative')
'''对数坐标''' plt.semilogx(x,y) # 对x取对数
plt.semilogy(x,y) # 对y取对数
plt.loglog(x,y) # 同时取对数
'''颜色填充''' fig = plt.figure() ax = fig.add_subplot()
ax.fill_between(x,y,y1,facecolor='b')
ax.grid(True) ax2 = fig.add_subplot()
ax2.fill(x,y,facecolor='b',alpha=0.3)
ax2.fill(x,y1,facecolor='g',alpha=0.3)
ax2.grid(True)
# plt.show()
'''三维绘图''' from mpl_toolkits.mplot3d import Axes3D u = np.linspace(-,,)
x,y = np.meshgrid(u,u) # 网格坐标生成函数
z = x**+y** fig = plt.figure()
ax = Axes3D(fig)
# cmap = color_map,另外两个参数是瓦片步长
ax.plot_surface(x,y,z,rstride=,cstride=,cmap='rainbow')
'''三维绘等高线图''' u = np.linspace(-,,)
x,y = np.meshgrid(u,u) # 网格坐标生成函数
z = x**+y** fig = plt.figure()
ax = fig.add_subplot()
ax.contourf(x,y,z)
plt.show()