Matplotlib's official website address: http://matplotlib.org/
When using Python to do data processing, a lot of the data we don't seem to be intuitive, and sometimes it's graphically shown that it's easier to observe the changing characteristics of the data, and so on.
Matplotlib is a Python 2D drawing library that generates publishing quality-level graphics in a variety of hard copy formats and cross-platform interactive environments. It provides a complete set of command APIs similar to MATLAB and is ideal for interactive mapping. It can also be conveniently embedded in GUI applications as a drawing control. With Matplotlib, developers can generate drawings, histograms, power spectra, bar graphs, error graphs, scatter graphs, and so on, with just a few lines of code.
Here's an example of the 51CTO Tang Yudi Teacher's matplotlib video course.
Data for the United States statistics of the unemployed population ratio:
Import pandas as PD # importing Pandas library to process CSV file import
matplotlib.pyplot as PLT # import Matplotlib.pyplot and plt abbreviation
unrate = PD. Read_csv (' Unrate.csv ') # read CSV file
unrate[' Date ' = Pd.to_datetime (unrate[' Date '])
# through Pd.to_ The DateTime function converts the Strin data type of the ' DATE ' property data in the Unrate.csv file to time type
print (Unrate.head (12)) # Print to view the first 12 rows of data
First_twelve = UNRATE[0:12] # Take the first 12 rows
of data plt.plot (first_twelve[' Date ', first_twelve[' value ') # to draw a line chart, ' Date ' column as the x axis, ' VALUE ' column as the y axis. Just use the two columns in the CSV file as x and Y, in the actual application, just specify a good data x and corresponding y.
Plt.xticks (rotation=30) # Sometimes the x-axis label is longer, it will overlap, where the rotation of a certain angle can be more convenient to display, the following figure
Plt.xlabel (' Month ') # to the x-axis data plus name
Plt.ylabel (' Unemployment Rate ') # Add name to Y-axis data
plt.title (' monthly unemployment Trends, 1948 ') # Add title
to entire chart Plt.show () # to show the pictures just drawn