Python Data Visualization-matplotlib Learning Notes (1)--line chart For example drawing primer __python

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.