import numpy as np
import matplotlib.pyplot as pp
x = np.arange(11)
y = np.random.randint(100, size = 11)
Numerical values are arranged from 0 to 10 on the x-axis. On the y-axis, 10 arrays consisting of random numbers from 0 to 100 are arranged.
pp.plot(x, y)
pp.axis([0, 10, 0, 100])
pp.xticks([dg for dg in np.arange(11)])
pp.grid(True)
The data is plotted on the first line. The second line specifies the x-axis display range and the y-axis display range. The third line has one scale on the x-axis. By the way, if you want to specify the scale on the y-axis as well, use the yticks function. Then, a grid is created from the scale with the grid function that takes True as an argument on the fourth line.
pp.show()
The following code can be summarized up to this point.
randplot.py
import numpy as np
import matplotlib.pyplot as pp
x = np.arange(11)
y = np.random.randint(100, size = 11)
pp.plot(x, y)
pp.axis([0, 10, 0, 100])
pp.xticks([dg for dg in np.arange(11)])
pp.grid(True)
pp.show()
Click here for the completed graph
Recommended Posts