current position:Home>Analysis of Matplotlib module of Python visualization

Analysis of Matplotlib module of Python visualization

2022-01-31 06:08:50 Little cute in the circle of friends

This is my participation 11 The fourth of the yuegengwen challenge 8 God , Check out the activity details :2021 One last more challenge


In the age of Internet , In the network, a lot of data will be generated every day , After analyzing the data , How to better interpret the meaning behind the data , We need to visualize the data .

In data visualization ,Python Also supports third modules.

  • matplotlib modular :Python Most used visualization Libraries
  • seaborn modular : be based on matplotlib Graphic visualization of
  • pycharts modular : Used to generate Echarts Class library for diagrams


In this issue , We are right. matplotlib Module provides graphical methods for learning ,Let's go~

1. matplotlib The module overview

matplotlib Modules are third-party open source , from John Hunter Developed by the team ,NumFOCUS Sponsored projects .

matplotlib The module is for Python Create static 、 Dynamic and interactive visual integrated library .


  • matplotlib Module features

    • Easy to create charts, such as publishing quality charts 、 Interactive data can be enlarged 、 narrow
    • Custom charts have complete control over line styles 、 Import and embed multiple file formats
    • High expansibility , Compatible with third-party modules
    • matplotlib The module reference manual is informative , But get started quickly
  • matplotlib Module acquisition

    matplotlib yes Python Mainstream third-party visualization module , We need to use pip Download

    pip install matplotlib
     Copy code 
  • matplotlib Module USES

    stay matplotlib Module ,pyplot Class is the most commonly used .

    • Mode one :
    from matplotlib import pyplot
     Copy code 
    • Mode two :
    import matplotlib.pyplot as plt
     Copy code 

Important note

  1. matplotlib Module official information
  2. see matplotlib Internal code description


2. matplotlib.pyplot Related methods

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

Method effect
pyplot.title(name) The title of the chart
pyplot.xlabel(name) Chart's X Axis name
pyplot.ylabel(name) Chart's y Axis name Print out the 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) Draw a scatter plot
pyplot.subplot(data) Draw a subgraph
pyplot.grid(boolean) Display mesh , The default is False
pyplot.text() Process the text
pyplot.pie(data) Draw the pie chart
pyplot.boxplot(data) Drawing box diagram
pyplot.hist(data) Draw histogram

3. matplotlib.pyplot Chart display

  • Draw line chart

    • Use pyplot..plot() Method
    from matplotlib import pyplot
    #  Format chart font 
    pyplot.title("data analyze")
     Copy code 


  • Draw a histogram

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


  • Draw the pie chart

    • Use pyplot.pie() Method to draw a pie chart
    • Use at the same time 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")
     Copy code 


  • Draw a scatter plot

    • Use pyplot.scatter(x,y) 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(" Elements  a")
    pyplot.ylabel(" Elements  b")
     Copy code 



In this issue , We are right. matplotlib.pyplot Draw relevant modules, such as broken lines 、 Columnar 、 Scatter 、 Simply learn the pie chart

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

The above is the content of this issue , Welcome big guys to praise and comment , See you next time ~

copyright notice
author[Little cute in the circle of friends],Please bring the original link to reprint, thank you.

Random recommended