[GO] A python graphing manual with Matplotlib.

Super-basic Matplotlib graph generation

Please copy and change it for yourself. This article is a drawing of a linear function of x.

  1. Library import
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
  1. Expression description

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 スクリーンショット 2020-06-27 13.29.53.png

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

A python graphing manual with Matplotlib.
Heatmap with Python + matplotlib
Visualize grib2 on a map with python (matplotlib)
Twitter graphing memo with Python
Make a fortune with Python
Create a directory with python
[Python] How to draw a line graph with Matplotlib
Forcibly draw something like a flowchart with Python, matplotlib
[Python, ObsPy] I wrote a beach ball with Matplotlib + ObsPy
[Python] How to create a 2D histogram with Matplotlib
[Python] How to draw a scatter plot with Matplotlib
[Python] Road to a snake charmer (5) Play with Matplotlib
[Python] What is a with statement?
Solve ABC163 A ~ C with Python
Operate a receipt printer with python
[Python] font family and font with matplotlib
Let's make a GUI with python.
Solve ABC166 A ~ D with Python
Draw a loose graph with matplotlib
Let's create a PRML diagram with Python, Numpy and matplotlib.
Create a virtual environment with Python!
I made a fortune with Python.
Building a virtual environment with Python 3
Solve ABC168 A ~ C with Python
Make a recommender system with python
Heatmap with Dendrogram in Python + matplotlib
[Python] Generate a password with Slackbot
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
Let's make a graph with python! !!
Draw Lyapunov Fractal with Python, matplotlib
When matplotlib doesn't work with python2.7
[Python] Inherit a class with class variables
I made a daemon with Python
Lognormal probability plot with Python, matplotlib
Write a stacked histogram with matplotlib
Write a batch script with Python3.5 ~
[Pyenv] Building a python environment with ubuntu 16.04
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Create a Python function decorator with Class
[Python] A program that creates stairs with #
Building a Python3 environment with Amazon Linux2
[Python] Set the graph range with matplotlib
Let's make a shiritori game with Python
Install Python as a Framework with pyenv
Build a blockchain with Python ① Create a class
Add a Python data source with Redash
Create a dummy image with Python + PIL.
I made a character counter with Python
Try drawing a normal distribution with matplotlib
[Python] Drawing a swirl pattern with turtle
I drew a heatmap with seaborn [Python]
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
A memo with Python2.7 and Python3 on CentOS
Building a Python 3.6 environment with Windows + PowerShell
Map rent information on a map with python
Search the maze with the python A * algorithm
Make a partially zoomed figure with matplotlib
Daemonize a Python web app with Supervisor