Axis adjustment and scale adjustment see: "Python" pil&plt image Processing _ Matrix conversion & Save diagram sharpness adjustment
Data generation:
1 import NumPy as NP2 import Matplotlib.pyplot as Plt3 4Func = np.poly1d (Np.array ([1,2,3,4]))5func1 = Func.deriv (m=1) # to find a derivative of the first order6Func2 = Func.deriv (m=2) # to find second derivative7 8x = Np.linspace (-Ten,Ten, -)9y =func (x)TenY1 =func1 (x) Oney2 = Func2 (x)
1 " " Normal Drawing " " 2 3 plt.plot (x, y,'ro', x,y1,'g--') 4 Plt.xlabel ('x')5 plt.ylabel (' y ' )6 plt.show ()
1 "' addSub-chart" "2 3Plt.subplot (311)4Plt.plot (x,y,c='R', linestyle='-')5Plt.title ('polynomial')6 7Plt.subplot (312)8Plt.plot (x,y1,c='b', linestyle="', marker='^')9# Plt.plot (X,y1,'b^')TenPlt.title ('First derivative') One APlt.subplot (313) -Plt.plot (x,y2,c='g', linestyle="', marker='o') -Plt.title ('Second derivative')
1 " " Logarithmic coordinates " " 2 3 PLT.SEMILOGX (x, y) # to x take logarithm 4plt.semilogy (y) # to Y take logarithm 5 Plt.loglog Y) # Take the logarithm at the same time
1 " "Color Fill" "2 3Fig =plt.figure ()4 5Ax = Fig.add_subplot (211)6Ax.fill_between (x,y,y1,facecolor='b')7 Ax.grid (True)8 9AX2 = Fig.add_subplot (212)TenAx2.fill (x,y,facecolor='b', alpha=0.3) OneAx2.fill (x,y1,facecolor='g', alpha=0.3) A Ax2.grid (True) -# plt.show ()
1 " "three-dimensional drawing" "2 3 From Mpl_toolkits.mplot3d import axes3d4 5U = Np.linspace (-1,1, -)6X, y =Np.meshgrid (u,u) # Grid coordinate generation function7z = x**2+y**28 9Fig =plt.figure ()TenAx =axes3d (Fig) One# cmap =Color_map, the other two parameters are the tile step size AAx.plot_surface (x,y,z,rstride=4, cstride=4, cmap='Rainbow')
1 " "three-dimensional plot contour plot" "2 3U = Np.linspace (-1,1, -)4X, y =Np.meshgrid (u,u) # Grid coordinate generation function5z = x**2+y**26 7Fig =plt.figure ()8Ax = Fig.add_subplot (111)9 Ax.contourf (x, Y, z)TenPlt.show ()
"Python" NumPy Learning Guide Chapter Nineth _ drawing with Matplotlib