Please copy and change it for yourself. This article is a drawing of a linear function of x.
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
Define a continuous x value in np.arange. In arange, the arithmetic progression data in the determined range is stored in the list. First argument: minimum range Second argument: Maximum range Third argument: Arithmetic progression The smaller the third argument, the smoother the graph.
x = np.arange(1.0,5.0,1) #0 from 1 to 5.Arithmetic progression in 01 increments
y = np.log(x) #Y function with argument x#Example:Logarithm
3, Graph depiction
Use the matplotlib.pylot function to draw the graph. Import it in advance. The pylot module is an interface for drawing graphs. A group of functions for drawing a graph is collected. There are two ways to draw a graph.
① Create an object that will be the basis of the graph, and use the pyplot method to create a graph element such as a line or bar graph. How to draw the axis labels etc. necessary for the graph (2) How to draw graph elements by directly calling the functions of the plot module
This time it's a simple depiction, so it's the latter method. This is an example of a simple depiction. As a flow
① Call the function of the pylot library and set the graph. ② Draw the graph information set in ① with the show function.
#Set graph information
#Horizontal(x axis)And vertical(y)Substitute axis values, set graph colors,
plt.plot(x,y,color = "red")
plt.ylabel('y-label') #x-axis title
plt.xlabel('x-label') #y-axis title
#Draw graph information
plt.show()
Execution result
The default color is black, so if you don't write it, it will be black. You can draw the graph settings in more detail, but you can draw the linear function with such a simple code.
Recommended Posts