1. Pandas Plotting
ImportMatplotlib.pyplot as PltImportNumPy as NPImportPandas as PD%matplotlib Notebookplt.style.use ("Seaborn-colorblind") Np.random.seed (123)#Cumsum:add value_of_i + value_of_i+1 = value_of_i+2DF = PD. DataFrame ({'A': Np.random.randn (365). Cumsum (0),'B': Np.random.randn (365). Cumsum (0) + 20, 'C': Np.random.randn (365). Cumsum (0)-20}, Index=pd.date_range ('1/1/2017', periods=365))#Create a scatter plot of columns ' a ' and ' C ', with changing color (c) and size (s) based on column ' B 'Df.plot.scatter ('A','C', c='B', s=df['B'], colormap='viridis')#Df.plot.box ();#df.plot.hist (alpha=0.7);#Df.plot.kde ();
#pd. Tools.plotting.scatter_matrix (Iris); Create Scater plots between the different variables and
#histograms aloing the diagonals to see the obvious patter
#pd. Tools.plotting.parallel_coordinates (Iris, ' Name ');
#visualizing high dimensional multivariate data, each variable in the data set corresponds to an equally spaced parallel V Ertical Line
Output:
2. Seaborn
ImportNumPy as NPImportPandas as PDImportMatplotlib.pyplot as PltImportSeaborn as SNS%matplotlib Notebooknp.random.seed (1234) V1= PD. Series (Np.random.normal (0,10,1000), name='v1') V2= PD. Series (2*v1 + np.random.normal (60,15,1000), name='v2')#plot a kernel density estimation over a stacked barchartplt.figure () plt.hist ([V1, v2], Histtype='barstacked', normed=True); V3=np.concatenate ((v1,v2)) Sns.kdeplot (v3);p lt.figure ()#we can pass keyword arguments for each individual component of the plotSns.distplot (v3, hist_kws={'Color':'Teal'}, kde_kws={'Color':'Navy'});p lt.figure ()#Sns.jointplot (v1, v2, alpha=0.4);#Grid = Sns.jointplot (v1, v2, alpha=0.4);#grid.ax_joint.set_aspect (' equal ')#Sns.jointplot (v1, v2, kind= ' hex ');#set the Seaborn style for all the following plots#sns.set_style (' white ')#Sns.jointplot (v1, v2, kind= ' KDE ', space=0); # space is used to set the margin of the joint plot
Output:
Joint plots
Second Example
Iris = Pd.read_csv ('iris.csv') sns.pairplot (iris, hue='Name ', diag_kind='KDE', size=2);
Third example
Iris = Pd.read_csv ('iris.csv') plt.figure (figsize= (8,6)) Plt.subplot ( 121) Sns.swarmplot ('Name''petallength', data= Iris);p lt.subplot (122) sns.violinplot ('Name ' Petallength ', Data=iris);
Output:
Data manipulation in Python (module 6)