Analysis of matplotlib module for Python visualization


In the Internet era, a lot of data will be generated in the network every day. After data analysis, we need to visually display the data to better interpret the meaning behind the data.

In data visualization, Python also supports third modules.

  • matplotlib module: the most used visualization Library in Python
  • seaborn module: graphic visualization based on matplotlib
  • pycharts module: a class library used to generate Echarts charts

In this issue, we learn the graphic methods provided by the matplotlib module, Let's go~

1. Overview of Matplotlib module

matplotlib module is a third-party open source module developed by John Hunter team and sponsored by NumFOCUS.

The matplotlib module is a comprehensive library for Python to create static, dynamic and interactive visualization.

  • matplotlib module features

    • Easy to create charts, such as publishing quality chart and interactive data, which can be enlarged and reduced
    • Customized charts can fully control line styles, import and embed a variety of file formats
    • High scalability, compatible with third-party modules
    • matplotlib module material manual is rich in information and can be used quickly
  • matplotlib module acquisition

    matplotlib is the mainstream third-party visualization module in Python. We need to download it using pip

    pip install matplotlib
     Copy code
  • The matplotlib module uses

  • python super full database installation package learning route project source code free sharing
    In the matplotlib module, the pyplot class is the most commonly used.

    • Mode 1:
    from matplotlib import pyplot
     Copy code
    • Mode 2:
    import matplotlib.pyplot as plt
     Copy code

🔔 Important note

  1. matplotlib module official information
  2. See matplotlib internal code description

matplotlib.pyplot related methods

matplotlib.pyplot  Module is one of the most commonly used modules for drawing icons

pyplot.title(name)Title of chart
pyplot.xlabel(name)X axis name of the chart
pyplot.ylabel(name)y-axis name of the chart out chart
pyplot.plot(xvalue,yvalue)Draw a line chart,yvalue)Draw a column chart
pyplot.axis(data)A convenient way to get or set some axis properties
pyplot.scatter(data)Scatter plot
pyplot.subplot(data)Draw subgraph
pyplot.grid(boolean)Display mesh, the default is False
pyplot.text()Process text
pyplot.pie(data)Draw pie chart
pyplot.boxplot(data)Draw box diagram
pyplot.hist(data)Draw histogram

3. matplotlib.pyplot chart display

  • Draw a line chart

    • Use the pyplot..plot() method
    from matplotlib import pyplot
    # Format chart font
    pyplot.title("data analyze")

  • Draw histogram

    • Use the method
    • Using the above data again, you can see the histogram[1,2,3,4,5,6],[45,20,19,56,35,69])
    Copy code

    Draw pie chart

  • Use the pyplot.pie() method to draw a pie chart
  • At the same time, use the pyplot.axis method to set the interval of each partition

Draw pie chart

use pyplot.pie () method to draw a pie chart, and use pyplot.axis method to set the interval of each partition

from matplotlib import pyplot
labels = ["windows","MAC","ios","Android","other"]
sizes = [50,10,5,15,20]
explode = [0,0.1,0,0,0]

pyplot.title("data analyze")

Scatter plot

  • Use pyplot.scatter(x,y) to draw a scatter plot
import numpy as np
from matplotlib import pyplot

data = {"a":np.arange(50),"c":np.random.randint(0,50,50),"d":np.random.randn(50)}

data['b'] = data['a']+10*np.random.randn(50)
data['d'] = np.abs(data['d'])*100


pyplot.title("data analyze")
pyplot.xlabel("element a")
pyplot.ylabel("element b")


In this issue, we will simply learn about the matplotlib.pyplot module drawing related charts such as broken line, column, scatter point and round cake

In the process of learning, we found that the pyplot module is easy to use, and all our data is the key point before presentation

The above is the content of this issue. Welcome to praise and comment. I'll see you next time~


Tags: Python Javascript Programmer Data Analysis echarts

Posted on Wed, 10 Nov 2021 10:26:19 -0500 by marcusb