The environment uses the environment created in the previous article. → Building Anaconda python environment on Windows 10 Please refer to the previous article for how to use numpy. → #Python basics (#Numpy 1/2) → #Python basics (#Numpy 2/2)
Graph drawing: Use pyplot
module
Draw on jupyter lab: % matplotlib inline
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-5, 5, num=10) # -Divide from 5 to 5 into 10
# x = np.linspace(-5, 5) #The default is 50 splits
print(x)
print(len(x)) #Number of elements of x
Execution result
[-5. -3.88888889 -2.77777778 -1.66666667 -0.55555556 0.55555556
1.66666667 2.77777778 3.88888889 5. ]
10
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-5, 5) # -From 5 to 5
y = 2 * x #Multiply x by 2 to get the y coordinate
plt.plot(x, y)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-100, 100, num=1000)
y_1 = x * x.T # x.T :1 row 1000 columns → Transposed to 1000 rows 1 column
y_2 = 10 * x
#Axis label
plt.xlabel("x val")
plt.ylabel("y val")
#Graph title
plt.title("Graph Name")
#Specify plot legend and line style
plt.plot(x, y_1, label="y1")
plt.plot(x, y_2, label="y2", linestyle="dashed")
plt.legend() #Show legend
plt.show()
import numpy as np
import matplotlib.pyplot as plt
x = np.array([1.2, 2.4, 0.0, 1.4, 1.5])
y = np.array([2.4, 1.4, 1.0, 0.1, 1.7])
plt.scatter(x, y) #Scatter plot plot
plt.show()
import numpy as np
import matplotlib.pyplot as plt
img = np.linspace(0, 100,num=100) #Divide 0 to 100 into 100 equal parts
print(img)
img = img.reshape(10,10) # 10 *10 Transformed into a matrix
plt.imshow(img, "gray") #Display in grayscale
plt.colorbar() #Color bar display
plt.show()
Recommended Posts