Today I will try to make the first graph with python. If you are wondering how to make Gulag with python, please go to see it after killing time. As I will explain for reference, this development environment uses ** Colaboratory **, which is an extension of the service of google dive, but it should be usable in other environments as well. If you want to do it in this environment, please refer to here. Basically, you can skip the preparation, but if you can't display the graph, please review the preparation.
Before we start, I will explain roughly how to make a graph. First python Install a library called ** matplotlib ** of the external library that is useful for creating graphs, store the data of points on the x-axis and y-axis in a list type, and finally a function called plot of the external library. The flow is that the graph is generated by substituting the previous data into. It is not necessary in this environment, but let's try installing the library in the terminal. Execute the following command.
pip install matplotlib
This completes the library installation. If that doesn't work, try entering this command. This completes the preparation.
I will give you the code first, so please give it a try. After that, I will explain it line by line.
#Define to use an external library
import matplotlib.pyplot as plt
#0 in the list~Order the number of 9s in a list.
x = list(range(10))
y = list(range(10))
#Create a graph based on x and y.
plt.plot(x, y);
If you actually execute the code like this, you will get a graph like this. I was able to create a graph firmly! I will explain the code immediately. The first line uses ** import ** to load the library. The last ** as ** is like calling the library with the name plt.
The 2nd and 3rd lines store 0 to 9 consecutive numbers in x and y in a list type. The numbers in parentheses in the range are used to generate consecutive numbers, which are stored one by one in the list.
In the 4th line, x and y are read into the ** plt ** defined earlier to create a graph. This is the end of the explanation.
Thank you for reading the article until the end. I'm a beginner, so if you find something wrong, please let me know in the comments.
A wonderful article that I referred to this time: https://techacademy.jp/magazine/17472
Recommended Posts