Seaborn is a very powerful data visualization library in Python. It integrates with Matplotlib. The following figure shows seaborn's official website. http://seaborn.pydata.org/
As you can tell from seaborn's home page, it's really powerful for data visualization.
1. First of all, we still need to import into the library, but this time we need to use more Python libraries.
The import numpy as np
The import pandas as pd
The import matplotlib as MPL
The import matplotlib. Pyplot as PLT
The import seaborn as SNS
2. Ss.set_style () : The default theme style is seaborn, which has five parameters
darkgrid
whitegrid
dark
white
ticks
I'm more comfortable with Whitegrid.
3. Next, the palette in
Seaborn can be retrieved from the palette(SNS. Color_palette () and printed from it using SNS. Palplot (). The color_palette() function can also pass in parameters
Nss.palplot (NSS.color_palette (" HLS ",n))# displays n color blocks of different colors
Palplot (NSs.color_palette ("Paired",2n))# shows 2n different color blocks that are close to each other
Nss.palplot (NSs.color_palette ("color"))# show blocks of the same color from shallow to deep
Nss.palplot (NSs.color_palette ("color_r"))## Shows blocks of the same color by depth palette
Nss.palplot (NSS.color_palette ("cubehelix",n))# shows n color blocks with linear variations of colors
Nss.palplot (nss.cubehelix_palette (k,start=m,rot=n))# shows k palette blocks with linear variations of start(0,3) m and rot(-1,1) n
Nss.palplot (NSs.light_palette ("color"))# to display a color from light to dark
Nss.palplot (NSs.dark_palette ("color"))# to display a color from dark to light
Nss.palplot (nss.dark_palette ("color",reverse=bool))#reverse to False, displays a color from dark to light; If True, displays a color from light to dark
4. Nss.kdeplot (X,y, Cmap = Pal) : draw the kernel density distribution.
Distplot (x,kde=bool,bins=n) : KDE represents whether the kernel density is estimated, that is, whether the envelope is drawn, and bins specify the number of bars drawn.
6. Plot according to mean value and covariance:
So the first thing we're going to do is get the data based on the mean and the covariance
Mean,cov = [m,n],[(a,b),(c,d)]# specify mean and covariance
Data = np.random. Multivariate_normal (mean,cov,e)# get e random data with the mean and covariance together with the latter as an latter
DataFrame(data,columns=["x","y"]
df
And then draw the image
Jointplot (x="x",y="y",data=df) # plot a scatter plot
Jointplot (x="x",y="y",data=df) can plot the bar graph of x and y with single variables and scatter plot of x and y with multiple variables.
7. The kind= "hex" passed in the jointplot() function enables us to see the percentage of data distribution more clearly when the number of data is large.
X, y = np. Random. Multivariate_normal (mean, cov, 2000). T
With SNS. Axes_style (" white ") :
SNS. Jointplot (x = x, y = y, kind = "hex", a color = "c")
8. Nss.pairplot (DF) : Draw the scatter graph and bar graph between each variable, and the diagonals are all bar graphs.
Here we can first use DF = nsS.load_dataset ("") to read in or read from seaborn the data that was originally contained.
9. Plot regression analysis diagram: The two functions regplot() and lmplot() can be used here, and regplot() is better.
If two variables are not suitable for regression analysis, we can pass in x_jitter() or y_jitter() to give the x or Y axis data a slight wobble to get a more accurate result.
10. Nss.stripplot (x="",y="",data= DF, Jitter =bool) : Draw a scatter plot of multiple variables in one feature variable in relation to another,jitter controls whether the data jitter.
11. SNS. Swarmplot (x="",y="", Hue ="",data= DF) : Draw a page-shaped scatter plot,hue specifies the classification of the data.
12. Boxplot (x="",y="", Hue ="",data= DF, Orient ="h") : The boxplot is drawn,hue also specifies the data classification. Quartile in statistics, the concept of the first quartile for Q1, the second quartile for Q2, the third quartile for Q3, Q3 - Q1 results Q is called the interquartile range, if a number n, n is the scope of n or n > < Q1-1.5 Q Q3 + 1.5 Q, is called n, outliers, that is, the point is not in conformity with the specification data, using the box figure, outliers can be seen clearly. If you pass in an Orient you draw a box horizontally.
13. Nss.violinplot (x="",y="",data=df,hue="",split=bool) : draw the violinplot,split means whether to draw the two types of data separately.
14. You can also draw a page scatter diagram and a violin diagram together by using just two drawing commands
Inner ="None" means to remove the shape inside the violin diagram.
15. SNS. Barplot (x = "", y =" ", hue = ", "data = df) : according to the data classification of hue draw a bar chart.
16. Pointplot (x="",y="",hue="",data=df) : draw a pointplot, which can better describe the variation of data.
17. We can also pass in other parameters:
SNS. Pointplot (x = "class", y = "survived", hue = "sex", many years ago data =,
The palette = {" male ":" # 02 ff96 ", "female" : "# 0980 e6}", # to specify the color of the curve
Markers = (" s ", "d"), linestyles = [" - ", "-"]) # specifies the point type curve and linear
18. Nss.factorplot (x="", y="", Hue ="", data= DF) : Draw multi-layer panel classification graph.
SNS. Factorplot (x = "day", y = "total_bill hue =" smoker ", data = tips)
The image drawn is shown below
19. SNS. Factorplot (x = "", y =" ", hue = ", "data = df, kind =" ") : a kind of type of the specified to drawing.
SNS. Factorplot (x = "day", y = "total_bill hue =" smoker ", data = tips, kind = "bar")
SNS. Factorplot (x = "day", y = "total_bill hue =" smoker ", col = "time", data = tips, kind = "swarm")
Ns. Factorplot (x="time",y="total_bill", Hue ="day",data= TIPS,kind="box",size=5,aspect=0.8) #aspect specified horizontal/vertical ratio
20. Nss.factorplot () parameters:
X,y, Hue data set variable variable name.
Date dataset Data set name.
Row,col more class variables tiled to display variable names.
The highest tiled integer per line of COL_wrap.
Estimator performs vector-to-scalar mapping vectors in each category.
Ci confidence interval floating point or None.
The integer number of boot iterations used when n_boot calculates the confidence interval.
The identifier of the Units sampling unit used to perform multiple boot and repeat measurements of design data variables or vector data.
Order, hue_Order corresponds to the sorted list string list.
Row_order, col_order corresponds to the sort list string list.
Kind: Optional: By default, bar bar, count frequency, Box, violin, strip, Swarm scatter point size per face height (in) scalar aspect aspect ratio scalar Orient "V "/"h" color color matplotlib color palette Seaborn color palette or legend Hue information palette True/False legend_out whether to extend graphics, Draw the information box on the right side of the center.
Nss.facetgrid () : This is an important drawing function.
G = SNS. FacetGrid (tips, col = "time")
G. ap (PLT) hist, "tip")
G = SNS. FacetGrid (tips, col = "sex", hue = "smoker", size = 5, the aspect = 1)
G. merap (plt.scatter,"total_bill","tip",alpha=0.3,s=100)#alpha transparency of dot,s size of dot
G. dd_legend()# Add legend
G = SNS. FacetGrid (tips, col = "day", size = 4, the aspect = 0.8)
G. ap (SNS) barplot, "sex", "total_bill)"
22. Nss.pairgrid () : Draw the relationships between variables in pairs.
Iris = SNS. Load_dataset (" iris ")
G = SNS. PairGrid (iris)
G. the ap (PLT) scatter)
23. G.ap_diag () and G.ap_offdiag () : Draw diagonals and diagonals
G = SNS. PairGrid (iris)
G.map_diag (plt.hist) # specifies the diagonal drawing type
G. Mer_offdiag (plt.scatter) # specifies the off-diagonal drawing type
G = SNS. PairGrid (iris, hue = "species")
G. ap_diag (PLT. Hist)
G. ap_offdiag (PLT) scatter)
G.a dd_legend ()
G = NSs.pairGrid (Iris, vars=["sepal_length", "sepal_width"], Hue ="species",size=3)
G. the ap (PLT) scatter)
G = NSS.pairgrid (tips, Hue ="size", palette="GnBu_d")
G. ap (PLT) scatter, s = 50, edgecolor = "white")
G.a dd_legend ()