Let's make a graph with python! !!

Audience of this article

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.

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.

Let's actually draw and see.

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. スクリーンショット 2020-08-25 22.42.42.png 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.

At the end

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

Let's make a graph with python! !!
Let's make a GUI with python.
Let's make a shiritori game with Python
Let's make a voice slowly with Python
Let's make a web framework with Python! (1)
Let's make a Twitter Bot with Python!
Let's make a web framework with Python! (2)
Make a fortune with Python
[Let's play with Python] Make a household account book
Let's make a breakout with wxPython
Let's make a simple game with Python 3 and iPhone
Make a recommender system with python
Let's make a supercomputer with xCAT
Make a nice graph with plotly
[Super easy] Let's make a LINE BOT with Python.
Let's make a websocket client with Python. (Access token authentication)
Let's create a free group with Python
Let's make a simple language with PLY 1
Let's make a tic-tac-toe AI with Pylearn 2
Let's make a combination calculation in Python
Make a desktop app with Python with Electron
[Python] Make a graph that can be moved around with Plotly
Let's make a positive / negative judgment tool into a band graph (Python)
Let's make a web chat using WebSocket with AWS serverless (Python)!
Make a Twitter trend bot with heroku + Python
[Python] Make a game with Pyxel-Use an editor-
[Python] Draw a directed graph with Dash Cytoscape
I want to make a game with Python
Try to make a "cryptanalysis" cipher with Python
[Python] Make a simple maze game with Pyxel
Try to make a dihedral group with Python
Let's make a module for Python using SWIG
[Ev3dev] Let's make a remote control program by Python with RPyC protocol
Let's make a Discord Bot.
Draw a graph with NetworkX
Let's run Excel with Python
Let's make Othello with wxPython
Make a bookmarklet in Python
Let's write python with cinema4d.
Create a directory with python
Let's make a rock-paper-scissors game
Let's build git-cat with Python
Draw a graph with networkx
Make a fire with kdeplot
Make one repeating string with a Python regular expression.
[Python] How to draw a line graph with Matplotlib
Try to make a command standby tool with python
[Practice] Make a Watson app with Python! # 2 [Translation function]
[Practice] Make a Watson app with Python! # 1 [Language discrimination]
Make a simple Slackbot with interactive button in python
Make a breakpoint on the c layer with python
Let's make dependency management with pip a little easier
[For play] Let's make Yubaba a LINE Bot (Python)
Make a CSV formatting tool with Python Pandas PyInstaller
Let's make a Mac app with Tkinter and py2app
Let's make a spherical grid with Rhinoceros / Grasshopper / GHPython
What is God? Make a simple chatbot with python
[Piyopiyokai # 1] Let's play with Lambda: Creating a Python script
If you want to make a discord bot with python, let's use a framework
Get the stock price of a Japanese company with Python and make a graph
Let's make a remote rumba [Hardware]