pandas_matplot_seaborn

import pandas as pd
#import matplotlib
#unrate= pd.read_csv("unrate.csv")
# 把时间格式 1948/1/10 转化为 1948-01-10
#unrate["DATE"] = pd.to_datetime(unrate['DATE'])
#折线图
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandas as pd
from scipy import stats, integrate
import matplotlib.pyplot as plt
import matplotlib as mpl

titannic = sns.load_dataset("titanic")
tips = sns.load_dataset("tips")
iris =sns.load_dataset('iris')
'''
admission = pd.read_csv(admissions.csv")
admission_t = admission[0:12]
plt.plot(admission_t['gpa'],admission_t['gre ']) # Draw pattern
plt.xticks (rotation = 25) # x axis to change the angle of the tag name
# add axis title
plt.xlabel ( "Hello")
plt.ylabel ( "World")
# add title
plt.title ( "Hello World")
#plt the .Show ()


Fig plt.figure = (figsize = (3,3)) Paint # default interval
# ax1 = fig.add_subplot (2,2,1) # 2,2 representative of the size of the matrix represents the position
# ax2 = fig. add_subplot (2.2.2)
# = fig.add_subplot AX4 (2,2,4)
plt.show ()

unrate = pd.read_csv ( "admissions.csv")
Fig plt.figure = (figsize = (10,6 ))

Colors = [ 'Red', 'Green', "Blue", "Orange", 'Black']
for I in Range (. 5):
start_index = I * 12 is
end_index = (I +. 1) * 12 is
Subset = unrate [start_index: end_index]
label = STR (1958 + I) in the top right corner balloon #
plt.plot (subset [ "gpa"] , subset [ "gre"], c = colors [i], label = label)
position plt.legend (loc = 'best') # define splat


plt.show ()

FIG row # column
from numpy Import aRange
# must first acquire height data for each column in the data acquisition abscissa
reviews = pd.read_csv ( ". csv" ) # file object obtained the DataForm
cols = [ 'FILM', 'RT_usr_norm ',' IMDB_norm ']
norm_recives = Reviews [cols] # Serise

NUM_COLS = [' Frist ', "SECOND",' THIRD ',' Four ',' Five ']
bar_height norm_recives.ix = (0, NUM_COLS) .values # height bar graph
bar_positions = arange (5) + 0.75 # position bar graph

Fig, AX = plt.subplots ()
ax.bar = (bar_positions, bar_height, 0.3) # 0.3 width bar graph representative of the column into window

#plt.Show ()
# Form Series library DATa
#ax graphics operations
#
fig, AX = plt.subplots ()

ax.hist (norm_recives)

# load file
recive_csv = pd.read_csv ( "cleaned_loans2007.csv")
#cols = [ 'clo1', 'col2', 'col3', 'COL4']
#correct_csv = recive_csv [cols]

Fig, plt.subplots = AX ()
ax.hist (recive_csv [ 'revol_bal']) gives the column name #
# statistical distribution range of the same value and the number represented by the bar graph out
plt.show ()

#data visualzation

# import Paint package
#% matplotlib inline
DEF sinplot (= Flip. 1):
X = np.linspace (0,14,100) # 100 points found in the section (0,14)
for I in range (l, 7): # 6 lines Videos
plt.plot (x, np.sin (x + i * 5) * (7-i) * flip) # calculating the height of each point, and draw on a view
plt.show ()
#sinplot () function call #
#seaborn set the theme style:
#sinplot ()
sns.set_style ( 'whitegrid')
data = np.random.normal (size = (20,6 )) # + np.arange (6) / 2 # normal probability density function
# two-dimensional array of 20 rows and 6 columns
Print (data.shape)
Print (data)
sns.boxplot (data = data) loading data #
# plt.show () # attempt to appear
# sns.set_style ( 'ticket') # with short line segments
Print (Help (np.linspace))
#sinplot ( ) calls the function

dd = np.linspace (0,5,100) # 100 generates a random number between 0-5 and ordering
Print (type (dd))
Print (dd)

Import numpy AS NP
N =. 8
Y = np.zeros (N) # initialize a np.array 8 contains zeros
Print (Y)
X1 = np.linspace (0, 10, N, Endpoint = True) # 8 x coordinate generating
Print (X1)
X2 = np.linspace (0, 10, N, Endpoint = False)
Print (X2)
plt.plot (X1, Y, 'O') # Videos first

plt.plot (x2, y + 0.5, 'o') # Paint

plt.ylim ([- 0.5,. 1])

plt.show ()


sns.set_style () Set Style #
sns.despine (left = True)
with sns.axes_style ( 'darkgrid'):
plt.subplot (211) to # FIG sub-set style setting
sinplot ()
sns.set_context ( "Paper")
plt.figure (figsize = (8,6))

HLS color space

Current = sns.color_palette ()
set_palette ()
index

# sns.set (rc = { "figure.figsize" :( 6,6)})
Current = sns.color_palette ()
sns.palplot (sns.color_palette ( 'HLS',. 8)) relating to color change #

# discrete continuous
#data = np .random.normal (size = (20,8)) + np.arange (. 8) / 2
# sns.boxplot (data = data, Palette = sns.color_palette ( 'HLS',. 4)) # type color display data attempt
Category # l brightness color saturation
# sns.color_palette ( 'hls', 8 , l = 7, s = 9)


plt.plot ([0.1], [0.1], sns.xkcd_rgb [ 'Pale Red'], = LW. 3)
plt.show ()

sns.palplot (sns.color_palette ( "Blue")) # gradient
sns.palplot ( sns.color_palette ( "Blue_r")) # gradient from dark to the front

sns.palplot (sns.cubechelix_palette (. 8, Start =. 5, rot = -75))
sns.palplot (sns.light_palette ( "Green")) # gradation

X, Y = np.random.multivariate_normal ([0,0], [[. 1, -5], [- 5,1]], size = 300) .T
Print (X, Y)
PAL = sns.dark_palette ( "Red", as_cmap = True)
# Videos volcano FIG
sns.kdeplot (x, y, cmap = pal) # passed in the position and color
plt.show ()
when the get data analysis univariate analysis wherein a single
data by wherein the composition, wherein the distribution of clear understanding


sns.set (color_codes = True)
AA = np.random.seed (SUM (Map (the ord, "distributions")))
Print (type (AA))
Print (AA)
X = np.random.normal (size = 100) # Gaussian data generated
#kde kernel density estimation higher bins segmentation Si Lunbu 20 aliquots distribution See Fit
X = np.random.gamma (. 6, size = 200 is)
# Square
sns.distplot (x, kde = False, fit = stats. gamma) # generates square FIG
plt.show ()

# relationship between the mean and covariance of the data features characterized by a scattergram wherein single square
mean, cov = [0,1], [(1, .5), (as .5, 1)]
data np.random.multivariate_normal = (Mean, CoV, 200 is) # generates two-dimensional data
df = pd.DataFrame (data, columns = [ 'x', 'y']) # format generated DataFrame data
# scattergram method
sns.jointplot (x = 'x', y = 'y', data = df) # scattergram generated
plt.show ()

Mean, CoV = [0,1], [(. 1, . .5), (5,1)]
X, Y np.random.multivariate_normal = (Mean, CoV, 1000) plus # .T .T into tuples
with sns.axes_style ( 'white'): # design hex type specified pattern king FIG
sns.jointplot (X = X, Y = Y, kind = 'hex', Color = 'K')
PLT.show ()
small amount of data played by the scattergram data amount hex FIG.


# Twenty-two wherein four feature comparison

IRIS = sns.load_dataset ( 'IRIS')
# visual characteristics and display characteristics between
sns.pairplot (IRIS)
plt.show ()

to draw a regression line type in FIG regplot ()

Tips = sns.load_dataset ( 'Tips')

Print (tips.head ())
# indexes x and y index relationship
# sns.regplot (x = 'total_bill', y = 'Tip', data = Tips)

# data jitter
sns.regplot (data Tips =, X = 'size', Y = 'Tip', x_jitter = .05)
plt.show ()



#strip FIG type
# sns.stripplot (y = 'day' , x = 'total_bill', data = tips, = False Jitter)

# tree of FIG type
# sns.swarmplot (X = 'Day', Y = 'total_bill', Data = Tips)
# cassette statistically FIG IQR interquartile range of one quarter and three quarters the distance between the bit
#N = 1.5IQR If a value> Q3 + n or <Q1-N is referred to as outlier
#sns.boxplot(x='day',y = 'total_bill',hue = 'time',data = tips)

#梯形图
#sns.violinplot(y = 'total_bill',x ='day',hue = 'time',data = tips,split= True)
#alpha = True #透明度
#柱形图
#sns.barplot(x = 'sex',y='survived',hue="class",data = titannic)

#点图
sns.pointplot(x = 'sex',y = 'survived',hue = 'class',data = titannic,palette={'male':'g','female':'m'},markers = ['^','o'],linestyles = ['-','--'])
#sns.pointplot(x = 'sex',y = 'survived',hue= 'class',data = titannic,palette={'male':'g','female':'m'},markers = ['^','o'],linestyles = ['-','-']) # plt.hist barinstantiate a FactGrid objects#G = sns.FacetGrid (Tips, COL =' Time ', hue =' smoker ')'' 'polytype FIG.")sns.factorplot (x = 'day',
# multilayer FIG





g.map # (plt.hist, 'Tip')
# scattergram
# g.map (plt.scatter, 'total_bill', 'Tip', Alpha =. 7)

# Specify drawing order:
from PANDAS Import Categorical
ordered_days = Tips .day.value_counts (). index
ordered_days Categorical = ([ 'Thur', 'Tri', 'Sat', 'the Sun'])
# ( 'assign a new sort')
G = sns.FacetGrid (Tips, Row = 'day', row_order = ordered_days, size = 7, aspect = 4) # create a FacetGrip objects
g.map (sns.boxplot, 'total_bill') # specifies the drawing mode and data

plt.show () # make images appear

Guess you like

Origin www.cnblogs.com/countryboy666/p/11223460.html