#Python basics (#matplotlib)

The environment uses the environment created in the previous article. → Building Anaconda python environment on Windows 10 Please refer to the previous article for how to use numpy. → #Python basics (#Numpy 1/2)#Python basics (#Numpy 2/2)

1. Matplotlib import

Graph drawing: Use pyplot module Draw on jupyter lab: % matplotlib inline

%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-5, 5, num=10)  # -Divide from 5 to 5 into 10
# x = np.linspace(-5, 5) #The default is 50 splits

print(x)
print(len(x))  #Number of elements of x

Execution result


[-5.         -3.88888889 -2.77777778 -1.66666667 -0.55555556  0.55555556
  1.66666667  2.77777778  3.88888889  5.        ]
10

2. Graph drawing

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-5, 5)  # -From 5 to 5
y = 2 * x  #Multiply x by 2 to get the y coordinate

plt.plot(x, y)
plt.show()

image.png

3. Title, legend, line style

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-100, 100, num=1000)
y_1 = x * x.T # x.T :1 row 1000 columns → Transposed to 1000 rows 1 column
y_2 = 10 * x

#Axis label
plt.xlabel("x val")
plt.ylabel("y val")

#Graph title
plt.title("Graph Name")

#Specify plot legend and line style
plt.plot(x, y_1, label="y1")
plt.plot(x, y_2, label="y2", linestyle="dashed")
plt.legend() #Show legend

plt.show()

image.png

4. Scatter plot

import numpy as np
import matplotlib.pyplot as plt

x = np.array([1.2, 2.4, 0.0, 1.4, 1.5])
y = np.array([2.4, 1.4, 1.0, 0.1, 1.7])

plt.scatter(x, y)  #Scatter plot plot
plt.show()

image.png

5. Image display

import numpy as np
import matplotlib.pyplot as plt

img = np.linspace(0, 100,num=100)  #Divide 0 to 100 into 100 equal parts
print(img)
img = img.reshape(10,10) # 10 *10 Transformed into a matrix
plt.imshow(img, "gray")  #Display in grayscale
plt.colorbar()   #Color bar display
plt.show()

image.png

Recommended Posts

#Python basics (#matplotlib)
Python basics ⑤
Python basics
Python basics ④
Python basics ③
Python basics
Python basics
Python basics
Python basics ③
Python basics ②
Python basics ②
Python basics: list
Python basics memorandum
Python CGI basics
Python basics: dictionary
Basics of Python ①
Basics of python ①
Python slice basics
#Python basics (scope)
#Python basics (#Numpy 1/2)
#Python basics (#Numpy 2/2)
My matplotlib (python)
#Python basics (functions)
Python array basics
Python profiling basics
Python #Numpy basics
Python basics: functions
#Python basics (class)
Python basics summary
Python basics ② for statement
Python: Unsupervised Learning: Basics
Python basics 8 numpy test
Errbot: Python chatbot basics
#Python DeepLearning Basics (Mathematics 1/4)
Heatmap with Python + matplotlib
Python basics: Socket, Dnspython
# 4 [python] Basics of functions
Basics of python: Output
Installation of matplotlib (Python 3.3.2)
Use matplotlib on Ubuntu 12 & Python
Python
Memorandum @ Python OR Seminar: matplotlib
python: Basics of using scikit-learn ①
Python application: data visualization # 2: matplotlib
Python basics: conditions and iterations
Paiza Python Primer 4: List Basics
Basics of Python × GIS (Part 1)
Basics of Python x GIS (Part 3)
Paiza Python Primer 5: Basics of Dictionaries
SNS Python basics made with Flask
Installation of SciPy and matplotlib (Python)
[Python] font family and font with matplotlib
[Python / matplotlib] Understand and use FuncAnimation
Getting Started with Python Basics of Python
Installation of Python, SciPy, matplotlib (Windows)
Review of the basics of Python (FizzBuzz)
Basics of Python x GIS (Part 2)
Heatmap with Dendrogram in Python + matplotlib
Draw Lyapunov Fractal with Python, matplotlib
When matplotlib doesn't work with python2.7
Lognormal probability plot with Python, matplotlib