Data Visualization (1)-Matplotlib Quick Start, visualization-matplotlib

Source: Internet
Author: User
Tags ggplot

Data Visualization (1)-Matplotlib Quick Start, visualization-matplotlib

Content source for this section: https://www.dataquest.io/mission/10/plotting-basics

Data source for this section: https://archive.ics.uci.edu/ml/datasets/Forest+Fires

Raw data display (this table records the fire in a park. X and Y represent the coordinates, and area represent the burned area)

import pandasforest_fires = pandas.read_csv('forest_fires.csv')print(forest_fires.head(5))

Import matplotlib. pyplot as plt

The process of plotting is divided into three steps:

1. initialize drawing data

2. Plotting

3. display the image

Scatter chart

Use the matplotlib. pyplot. scatter () method to create a scatter chart. The first parameter is the X axis and the second parameter is the Y axis. Note that both parameters can only be list data or Series

# Use the list data as the coordinate axis import matplotlib. pyplot as pltweight = [600,150,200,300,200,100,125,180] height = [60, 65,] plt. scatter (height, weight) plt. show ()

# Using Series as the coordinate axis # using wind as the X axis, burning area as the Y axis, and making their scatter plot plt. scatter (forest_fires ["wind"], forest_fires ["area"]) plt. show ()

Plt. scatter (forest_fires ['wind'], forest_fires ['region']) plt. title ('wind speed vs fire area') plt. xlabel ('wind speed when fire started') plt. ylabel ('area consumed by fire') plt. show ()

# Use the list data as the axis age = [5, 10, 15, 20, 25, 30] height = [25, 45, 65, 75, 75] plt. plot (age, height) plt. title ('Age vs height') plt. xlabel ('age') plt. ylabel ('height') plt. show ()

# Calculate the burned-out area by month # Calculate the burned-out area area_by_month = forest_fires.pivot_table (index = "month", values = "area", aggfunc = numpy. sum)

Plt. bar (range (len (area_by_month), area_by_month) plt. title ('month vs Region') plt. xlabel ('month') plt. ylabel ('area ') plt. show ()

Plt. barh (range (len (area_by_month), area_by_month) plt. title ('month vs Region') plt. xlabel ('area ') plt. ylabel ('month') plt. show ()

# Compare plt with the two themes. style. use ('maid ') plt. plot (forest_fires ['rain'], forest_fires ['region']) plt. show ()

Plt. style. use ('ggplot ') plt. plot (forest_fires ['rain'], forest_fires ['area']) plt. show ()

The following topics are generally used:

Fivethirtyeight, ggplot, dark_background, bmh

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.