meshgrid
. 1 Import numpy AS NP 2 from matplotlib Import pyplot AS PLT . 3 from mpl_toolkits.mplot3d Import Axes3D . 4 X = np.array ([ 0 , . 1 , 2 ]) . 5 Y = np.array ([ 0 , . 1 ]) . 6 X-, = the Y np.meshgrid (X, Y) X-#, expanded into the Y matrix, . 7 Print (X-) . 8 Print (the Y) . 9 theta0, Theta1, Theta2 = 2 , . 3 , . 4 10 AX = Axes3D (plt.figure ( )) used to draw three-dimensional map # 11* = Theta0 + Theta1 the Z + X-* Theta2 the Y value # z request 12 is plt.plot (X-, the Y, ' R & lt. ' ) # Then you will find a drawing is 3 * 2 points, which constitute a network grid, the coordinates of each point is cut * X- the Y Cartesian product 13 is ax.plot_surface (X-, the Y, the Z) used to draw three-dimensional map # 14 plt.show ()
Specific can refer to this blog
mpl_toolkits.mplot3d
The method is used when drawing paneled
Use add_subplot
import numpy as np import matplotlib.pyplot as plt x = np.arange(0, 100) fig = plt.figure() ax1 = fig.add_subplot(221) ax1.plot(x, x) ax2 = fig.add_subplot(222) ax2.plot(x, -x) ax3 = fig.add_subplot(223) ax3.plot(x, x ** 2) ax4 = fig.add_subplot(224) ax4.plot(x, np.log(x)) plt.show()
Use subplot method
import numpy as np from matplotlib import pyplot as plt x = np.arange(10) plt.subplot(221) plt.plot(x,x) plt.subplot(223) plt.plot(x,-x) plt.show()
PolynomialFeatures
1 import numpy as np 2 import matplotlib.pyplot as plt 3 from sklearn.preprocessing import PolynomialFeatures#多项式 4 from sklearn.linear_model import LinearRegression 5 6 # 载入数据 7 data = np.genfromtxt("job.csv", delimiter=",") 8 x_data = data[1:,1] 9 y_data = data[1:,2] 10 plt.scatter(x_data,y_data) 11 plt.show () 12 is # dimension must be two-dimensional 13 is x_data = x_data [:, np.newaxis] 14 y_data = y_data [:, np.newaxis] 15 # polynomial regression defined, can adjust the value of degree polynomial features 16 poly PolynomialFeatures = (Degree = . 4 ) . 17 # feature processing 18 is x_poly = poly.fit_transform (x_data) . 19 # define the regression model 20 is model = LinearRegression () 21 is # training model 22 is model.fit (x_poly, y_data) 23 is plt.plot (x_data , y_data, ' B. ' ) 24 plt.plot (x_data, model.predict (poly.fit_transform (x_data)),'r') 25 plt.show()