Introduction and simple operation of Matplotlib

Introduction and simple operation of Matplotlib


1 What is Matplotlib

  • Is specifically used to develop 2D charts (including 3D charts)
  • Realize data visualization in a progressive and interactive way

2 Why you should learn Matplotlib

Visualization is a key auxiliary tool in the entire data mining. It can clearly understand the data and adjust our analysis methods.

  • Can visualize data and present it more intuitively
  • Make the data more objective and persuasive

For example, the following two pictures are digital display and graphic display:

3 Implement a simple Matplotlib drawing — take a line chart as an example

3.1 matplotlib.pyplot module

matplotlib.pytplot contains a series of drawing functions similar to matlab.

import matplotlib.pyplot as plt

3.2 Graphics drawing process:

  • 1. Create a canvas - plt.figure()

  • plt.figure(figsize=(), dpi=)
        figsize:指定图的长宽
        dpi:图像的清晰度
        返回fig对象
    
  • 2. Plot the image - plt.plot(x, y)

  • 以折线图为例
    
  • 3. Display image - plt.show()

3.3 Drawing and display of line chart

Example: Show the weather of the week, such as the weather temperature from Monday to Sunday as follows

import matplotlib.pyplot as plt

# 1.创建画布
plt.figure(figsize=(10, 10), dpi=100)

# 2.绘制折线图
plt.plot([1, 2, 3, 4, 5, 6 ,7], [17,17,18,15,11,11,13])

# 3.显示图像
plt.show()

4 Know the structure of Matplotlib images

5 Summary

  • What is matplotlib
    • It is a package dedicated to the development of 2D (3D) charts
  • Drawing image process
    • 1. Create a canvas - plt.figure(figsize=(20,8))
    • 2. Plot the image - plt.plot(x, y)
    • 3. Display image - plt.show()

Guess you like

Origin blog.csdn.net/weixin_44799217/article/details/113833991