Python Visualization Library - Matplotlib And Seaborn

Source: Internet
Author: User
Keywords matplotlib seaborn seaborn python

Seaborn is a library for making statistical graphics in Python. It is built on top of matplotlib and closely integrated with pandas data structures.

Data visualization Library -- Matplotlib

import  matplotlib.pyplot  as plt
One
Default visualization
plt.plot (): Drawing
plt.show (): display
Set parameters
plt.xticks (rotation): variable name skew
plt.xlable ('variable name'): X-axis name
plt.ylabel ('variable name '): Y-axis name
plt.title (): title name
Subgraph
fig= plt.figure (): Specifies the default drawing space
fig.add_ Subplot (4,1, x): x stands for relative position
Add note: plt.legend (LOC = 'best') 'best' represents the position of the comment box
Drawing type: fig, ax= plt.subplots (), ax is the axis of drawing, the actual drawing; fig is used to set parameters
Column chart:
ax.bar (bar_ positions, bar_ Heights, 0.5), 0.5 for column width
ax.barh (): bar chart
Scatter: ax.scatter (x, y)
Histogram (with bins)
ax.hist (y, range (4,5), bins = 20), range sets the range of values
ax.set_ Ylim (0.5): set Y-axis range
Box chart: ax.boxplot ()
Add text to an element: ax.text (x, y, ‘text’)
Visual library --  Seaborn
import seaborn as sns
One
Seaborn library is an encapsulation based on Matplotlib library
Set style
sns.set (): default style
sns.set_ Style: 5 Styles
with  sns.axes_ Style: all statements under with use this style
layout
sns.despline (offset, left): set the offset and display of the axis
sns.set_ Context ("paper"): set the curve size in the graph
Palette: sns.color_ Palette () has six themes
Circular Sketchpad: sns.color_ palette(“hls”)
Paired: "paired"
Continuous type
sns.color_ Palette ("Blues"): from shallow to deep
sns.color_ palette(“Blues_ R "): from deep to shallow
sns.light_ Palette ("green"): from shallow to deep, reverse = true means from deep to shallow
sns.dark_ Palette ("green"): from deep to shallow
Line type: sns.cubehelix_ palette(8, start, rot)
Variable analysis
Univariate: sns.distplot (x, KDE, bins, fit) - histogram
x: Variable
KDN: estimation and density
Bins: divide the x-axis into several parts
Fit: distribution status
Bivariate
sns.jointplot (x, y, data) -- scatter plot
sns.jointplot (x, y, kind = "hex", color) - can reflect the data density
Multivariable
sns.pairplot (): reflect the relationship between two variables
sns.stripplot (x, y, data): not recommended. When the data volume is large, it is connected into a line
Optimization method:
sns.stripplot (x, y, data, jitter = true) - add a small amount of jitter
sns.swamplot (x, y, data) - tree
sns.violinplot (x, y, hue, data, split) - Violin diagram
Regression analysis: regplot, lmplot
sns.load_ Dataset - download data
sns.regplot (x, y, data, jitter)
Classification analysis
sns.barplot (x, y, hue, data): bar chart, depicting the overall trend
sns.pointplot (x, y, hue, data): point plot, depicting variation
sns.factorplot (x, y, data, kind): classification diagram of multi-layer panel
Facetgrid -- display subset
usage method
G= sns.FacetGrid (data, col)
g.map( plt.hist , variable)
Set parameters
g.set_ axis_ Labels(): name of the axis
g. Set (xticks, yticks): the value of X, y
G. fig.subplots_ Adjust (wspace, hspace): gap
Multivariable
g.PairGrid()
g.map_ diag()
g.map_ offdiag()
Heat map: sns.heatmap (data, vmin, vmax, center, annt,fmd, linewidth, cmap)
Annot: display numbers in each grid
FMD: display number format
Linewidth: distance between cells
CMAP: color map
Related Article

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.