Repeat simple things, repeat things insist on doing, insist on doing things with your heart; Your affirmation is I insist on the power, if this article is helpful to you, point a concern!
Dependent library
1# -*- coding: UTF-8 -*-
2
3"4DataFrame drawing 5" "
6# pandas Data extraction extension library
7
8import pandas as pd
9
10# Numpy Scientific computing library
11
12import numpy as np
13
14# matplotlib Data visualization library
15
16import matplotlib.pyplot as plt
Copy the code
DataFrame. The plot () function
1''' 2DataFrame.plot(x=None, y=None, kind='line', ax=None, subplots=False, 3 sharex=None, sharey=False, layout=None,figsize=None, 4 use_index=True, title=None, grid=None, legend=True, 5 style=None, logx=False, logy=False, loglog=False, 6 xticks=None, yticks=None, xlim=None, ylim=None, rot=None, 7 xerr=None,secondary_y=False, sort_columns=False, **kwds) 8'''
9
10# datafame.plot () function parameter configuration:
11# x: Horizontal marking position, default to None
12# y: Indicates the vertical position. Default is None
13# kind argument: Draw type (string)
14# 'kind=line' : line pattern
15# 'Kind =bar' : vertical bar pattern
16# 'Kind =barh' : Horizontal bar pattern
17# 'kind=hist' : bar pattern
18# 'kind=box' : box-plot mode
19# 'kind= kDE' : Density estimation graph mode
20# 'kind=area' : area map mode
21# 'kind=pie' : pie pattern
22# 'Kind = Scatter' : Scatter pattern
23# 'kind=hexbin' : Hive diagram mode
24
25# ax: subplot (if not set, use the current matplotlib subplot**)
26
27# subplots: any subplots in the plot. Default is False
28
29# sharex: Defaults to True if ax is None, False otherwise
30
31# sharey: defaults to False if there is a subgraph, the subgraph shares the y-scale label
32
33# layout: Row and column layout of a subgraph
34
35# figsize: Size of the image
36
37# use_index: defaults to False and uses the index as the X-axis
38
39# title: The title of the image is a string
40
41# grid: Defaults to None, whether the image has a grid
42
43# legend: indicates a sublegend. The default value is True
44
45# style: Set the line type for each column line chart
46
47# logx: Defaults to False and sets whether the X-axis scale is logarithmic
48
49# loglog: Defaults to False, and sets whether the x and y scales are logarithmic
50
51# xticks: set the xticks
52
53# yticks: set the yticks
54
55# xlim: Sets the range of the axes
56
57# ylim: Sets the range of the axes
58
59# rot: Defaults to None, setting the rotation degree of the axis TAB
60
61# fontsize: defaults to None, sets the fontsize for the axis scale
62
63# colormap: Defaults to None, setting the region color of the graph
64
65# colorbar: Picture column
66
67# position: the value ranges from 0 to 1. The default value is 0.5 to indicate middle alignment
68
69# layout: A few rows and columns
70
71# table: Defaults to False, selects DataFrame data and transforms to match the layout of Matplotlib
72
73# yerr : DataFrame, Series, array-like, dict and str
74
75# xerr : same types as yerr.
76
77# stacked : boolean, default False in line and
78
79# sort_columns: Defaults to False to sort column names in front order
80
81# secondary_y: Default False, whether to set the second Y axis
82
83# mark_right: The label on the Y-axis when the second Y-axis is used, which defaults to True
Copy the code
Constructing raw data
1Define raw data 3 ""
4# np.random. Randn generates a matrix with 4 rows and 4 columns
5
6# columns attribute
7
8# index index
9
10df = pd.DataFrame(np.random.randn(4.4),columns = ['a'.'b'.'c'.'d'],index=['2021-03-20'.'2021-03-21'.'2021-03-22'.'2021-03-23'])
11
12print(df)
Copy the code
Draw a line chart
12 Line chart 3 ""
4# graph (default line graph)
5
6# Set Chinese
7
8plt.rcParams['font.sans-serif'] = ['SimHei']
9
10The negative sign of the coordinate axis is not displayed properly and cannot display Chinese properly
11
12plt.rcParams['axes.unicode_minus'] =False
13
14df.plot(kind='line',color='b',title='Data change')
15
16plt.show()
Copy the code
Draw bar charts
1Bar chart 3"
4# Draw (bar chart mode)
5
6# fontsize fontsize
7
8# legend Example of a subgraph
9
10# figsize Indicates the size of the legend
11
12df.plot(kind='bar', title ="", figsize=(8.5), legend=True, fontsize=12)
13
14plt.show()
Copy the code
More exciting things to come to wechat public account “Python Concentration Camp”, focusing on Python technology stack, information acquisition, communication community, dry goods sharing, looking forward to your joining ~