Graph drawing in python

Drawing a line graph

Suppose you do this with a jupyter notebook. If you do it on the terminal, you need to save the graph to a file. To save it, use plt.savefig ("filename ").

Drawing with pyplot


#Library used for numerical calculation
import numpy as np
import pandas as pd

#Library for drawing graphs
from matplotlib import pyplot as plt

#Specification to display the graph in jupyter Notebook
%matplotlib inline

x = np.array([0,1,2,3,4,5,6,7,8,9])
y = np.array([2,3,4,3,5,4,6,7,4,8])

plt.plot(x, y, color = 'black')
plt.title("lineplot matplotlib")
plt.xlabel("x")
plt.ylabel("y")
スクリーンショット 2020-01-25 15.33.26.png

Drawing by seaborn


import seaborn as sns
sns.set()

plt.plot(x, y, color = 'black')
plt.title("lineplot seaborn")
plt.xlabel("x")
plt.ylabel("y")
スクリーンショット 2020-01-25 15.37.35.png

Histogram drawing


data = np.array([2,3,3,4,4,4,4,5,5,6])
sns.distplot(data, bins = 5, 
             color = 'black', kde = False)

<img width="300" height ="200"alt="hist.png " src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/512772/0c701442-e3c8-4214-8968-05731fb6c8b9.png ">

--Define how many groups the data should be divided into with bins. --Set the display / non-display of kernel density estimation [^ 1] with kde

[^ 1]: One of the nonparametric methods for estimating the probability density function of random variables in statistics.


sns.distplot(fish_data, color = 'black' norm_hist=True)
--`norm_hist` changes the vertical axis so that the total area of the histogram is 1.

Box plot

sns.boxplot(x = "species", y  = "length", 
            data = multi, color = 'gray')
スクリーンショット hako_hige.png

Violin plot

Using the result of kernel density estimation


sns.violinplot(x = "species", y  = "length", 
               data = multi, color = 'gray')

bar graph

sns.barplot(x = "species", y  = "length", 
            data = fish_multi, color = 'gray')
スクリーンショット 2020-01-25 16.08.15.png

Scatter plot


sns.jointplot(x = "x", y = "y", 
              data = cov_data, color = 'black')

Regression line

sns.lmplot(x = "temperature", y = "beer", data = D,
          scatter_kws = {"color": "black"},
          line_kws = {"color": "black"})
スクリーンショット 2020-01-29 13.12.50.png
sns.lmplot(x = "price", y = "sales", data = sales,
          hue = "weather", palette = "gray")
スクリーンショット 2020-01-29 13.15.02.png

reference

Shinya Baba, a textbook on statistics learned with new Python

Recommended Posts

Graph drawing in python
Draw graph in python
Drawing candle charts in python
From file to graph drawing in Python. Elementary elementary
Until drawing a 3D graph in Python on windows10
Ant book in python: Sec. 2-5 Graph
Quadtree in Python --2
Python in optimization
CURL in python
[python] Streamline drawing
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Try drawing a simple animation in Python
Ant book in python: Sec. 2-5 Graph (preparation)
Easily graph data in shell and Python
Create your own graph structure class and its drawing in python
Sorted list in Python
Daily AtCoder # 36 in Python
Clustering text in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python