Using the Data visualization tools matplotlib python and seaborn visualize the required data using Part numpy libraries and library generation pandas array, matrix, dataframe.
Import the required libraries:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
FIG drawing functions (plt.plot ())
Select the graphic theme
plt.sytle.use (): five kinds of themes: Dark Grid (darkgrid), white mesh (whitegrid), black (dark), all white (white), full scale (ticks) defaults to full scale
Plotted in FIG.
matplotlib.pyplot.plot (* args, scalex = True, scaley = True, data = None, ** kwargs): * args include the required data, color and style of curve
Display graphics
matplotlib.pyplot.show(args,* kw )
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use("seaborn-darkgrid")#定义x
x=np.arange(0,3*np.pi,0.1)#生成正弦函数
y=np.sin(x)#调用plot函数实现可视化
plt.plot(x,y)
plt.show()
Draw subgraph: the painting into a Bucher a subgraph above, relating to generation function
Add subgraph
matplotlib.pyplot.subplot (* args, ** kwargs): adding the current submap in FIG. * Args is an integer of 3 or an integer of three separate, the location descriptor of FIG.
plt.figure (figsize = (8,6), dpi = 80) # Create a 8x6 sized image, dpi = 80 indicates 80 points per inch resolution
Curve set color, width, label style
plt.plot (X, C, color = "blue", linewidth = 1.0, label = "Blue", linestyle = "-") C denotes a function of blue, a line width of one pixel, sign legend table " Blue ", linestyle a graph style
matplotlib.pyplot.scatter (x, y, s = None, c = None, marker = None, cmap = None, norm = None, vmin = None, vmax = None, alpha = None, linewidths = None, verts = None, edgecolors = None, *, data = None, ** kwargs): draw scattergram. X, y-axis data representing xy, s represents a scalar, c denotes color, marker tag indicates style.
a = np.random.randint(0,20,15)# 随机生成数据
b = np.random.randint(0,20,15)print(a)print(b)i
plt.scatter(a, b)# 绘制散点图
plt.show()
seaborn achieve Scatter: create dataframe
Draw a scatter plot
seaborn.jointplot (x, y, data = None, kind = 'scatter', stat_func = None, color = None, height = 6, ratio = 5, space = 0.2, dropna = True, xlim = None, ylim = None, joint_kws = None, marginal_kws = None, annot_kws = None, ** kwargs): with two variables are plotted. color: color; size: 6 default, the scale size of the map (squares); ratio: the ratio of the center of FIG. FIG side edge; space: FIG interval size and the center side map; s: the dot size; linewidth: line width; {x, y} lim: x, y-axis range.
matplotlib.pyplot.bar (x, height, width = 0.8, bottom = None, *, align = 'center', data = None, ** kwargs): a histogram. X: abscissa; height: height of the bar; width: each strip width, color: the color of each bar.
Add a grid display
plt.grid ()
seaborn achieve Histogram
seaborn.countplot (x = None, y = None, hue = None, data = None, order = None, hue_order = None, orient = None, color = None, palette = None, saturation = 0.75, dodge = True, ax = none, ** kwargs): histogram. x, y: xy axis; data: data; hue: forming a histogram classified according to the classification in the column name value; order, hue_order: histogram for controlling the sequence; palette: palette, controls a different color.
from pylab import mpl
mpl.rcParams['font.sans-serif']=['SimHei']# 解决中文不显示问题
level =['tk','shtk','hztk']
x =range(len(level))# 横坐标
y =[1,3,2]# 纵坐标
plt.figure(figsize=(4,3),dpi=80)# 创建画布
plt.bar(x, y, width=0.5, color=['b','r','g'])# 绘制柱状图
plt.xticks(x,level)
plt.grid(linestyle="--", alpha=0.5)# 添加网格显示
plt.show()
matplotlib.pyplot.hist (x, bins = None, range = None, density = None, weights = None, cumulative = False, bottom = None, histtype = 'bar', align = 'mid', orientation = 'vertical', rwidth = None, log = False, color = None, label = None, stacked = False, normed = None, *, data = None, ** kwargs): histogrammed. X: specify each bin (bin) of data distribution, corresponding to the x-axis; bins: Specifies the number of bin (box), i.e. a total of several bar chart; normed: specified density, that is, each bar graph the proportion ratio, the default is 1; color: specifies the color of the bar graph.
seaborn histogram for
seaborn.distplot (a, bins = None, hist = True, kde = True, rug = False, fit = None, hist_kws = None, kde_kws = None, rug_kws = None, fit_kws = None, color = None, vertical = False, norm_hist = False, axlabel = None, label = None, ax = None): histogrammed. A: Data; hist: whether to display the histogram; kde: whether kernel density estimation; bins: dividing the control histogram; fit: fitting parameter map control