可视化部分的学习
import matplotlib. pyplot as plt
import numpy as np
fig= plt. figure( )
ax= fig. add_subplot( 1 , 1 , 1 )
ax. plot( np. random. randn( 1000 ) . cumsum( ) )
ticks= ax. set_xticks( [ 0 , 250 , 500 , 750 , 1000 ] )
labels= ax. set_xticklabels( [ 'one' , 'two' , 'three' , 'four' , 'five' ] )
ax. set_title( 'My first matplotlib plot' )
ax. set_xlabel( 'Stages' )
plt. plot( )
plt. show( )
from numpy. random import randn
fig= plt. figure( )
ax= fig. add_subplot( 1 , 1 , 1 )
ax. plot( randn( 1000 ) . cumsum( ) , 'k' , label= 'one' )
ax. plot( randn( 1000 ) . cumsum( ) , 'k--' , label= 'two' )
ax. plot( randn( 1000 ) . cumsum( ) , 'k.' , label= 'three' )
ax. legend( loc= 'best' )
plt. plot( )
plt. show( )
fig= plt. figure( )
ax= fig. add_subplot( 1 , 1 , 1 )
rect= plt. Rectangle( ( 0.2 , 0.75 ) , 0.4 , 0.15 , color= 'k' , alpha= 0.3 )
circ= plt. Circle( ( 0.7 , 0.2 ) , 0.15 , color= 'b' , alpha= 0.3 )
pgon= plt. Polygon( [ [ 0.15 , 0.15 ] , [ 0.35 , 0.4 ] , [ 0.2 , 0.6 ] ] , color= 'g' , alpha= 0.5 )
ax. add_patch( rect)
ax. add_patch( circ)
ax. add_patch( pgon)
plt. plot( )
plt. show( )
习题训练
import numpy as np
import pandas as pd
import matplotlib. pyplot as plt
text= pd. read_csv( 'D:\\pythondata\\result.csv' )
print ( text. head( 5 ) )
sex= text. groupby( 'Sex' ) [ 'Survived' ] . sum ( )
sex. plot. bar( )
plt. title( 'survived_count' )
plt. show( )
text. groupby( [ 'Sex' , 'Survived' ] ) [ 'Survived' ] . count( ) . unstack( ) . plot( kind= 'bar' , stacked= True )
plt. title( 'survived_count' )
plt. ylabel( 'count' )
fare_sur= text. groupby( [ 'Fare' ] ) [ 'Survived' ] . value_counts( ) . sort_values( ascending= False )
print ( fare_sur)
fig= plt. figure( figsize= ( 20 , 18 ) )
fare_sur. plot( grid= True )
plt. legend( )
plt. show( )
fare_sur1= text. groupby( [ 'Fare' ] ) [ 'Survived' ] . value_counts( )
print ( fare_sur1)
fig= plt. figure( figsize= ( 20 , 18 ) )
fare_sur1. plot( grid= True )
plt. legend( )
plt. show( )