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