from jupyterthemes import jtplot
jtplot. style( theme= 'monokai' )
import matplotlib. pyplot as plt
% matplotlib inline
plt. figure( )
plt. plot( [ 1 , 0 , 9 ] , [ 4 , 5 , 6 ] )
plt. show( )
折线图绘制与显示
plt. figure( figsize= ( 20 , 8 ) )
plt. plot( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] , [ 17 , 17 , 18 , 15 , 11 , 11 , 13 ] , label= "hh" )
plt. legend( loc= "lower left" )
plt. grid( True , linestyle= '-' , alpha= 0.5 )
plt. show( )
绘制数学函数图像
import numpy as np
x = np. linspace( - 1 , 1 , 1000 )
y = 2 * x * x
plt. figure( figsize= ( 20 , 8 ) , dpi= 80 )
plt. plot( x, y)
plt. show( )
散点图绘制
x, y = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] , [ 17 , 17 , 18 , 15 , 11 , 11 , 13 ]
plt. figure( figsize= ( 20 , 8 ) )
plt. scatter( x, y)
plt. show( )
绘制柱状图
x, y = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] , [ 17 , 17 , 2 , 15 , 11 , 11 , 13 ]
plt. figure( figsize= ( 20 , 8 ) )
plt. bar( x, y, width= 0.5 , color= [ 'r' , 'b' , 'y' , 'g' ] )
plt. show( )
绘制直方图
x = [ 1 , 2 , 3 , 4 , 5 , 6 , 17 , 17 , 18 , 15 , 11 , 45 , 12 , 54 , 23 , 45 , 6 , 12 , 87 , 51 , 11 , 13 ]
plt. figure( figsize= ( 20 , 8 ) , dpi= 80 )
distance = 2
group_num = int ( ( max ( x) - min ( x) ) / distance)
plt. hist( x, bins= group_num)
plt. show( )
饼图
x, y = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] , [ '17' , '17' , '2' , '15' , '11' , '11' , '13' ]
plt. figure( figsize= ( 20 , 8 ) )
plt. pie( x, labels= y, autopct= '%1.2f%%' , colors= [ 'r' , 'b' , 'y' , 'g' ] )
plt. axis( 'equal' )
plt. legend( loc= "lower left" )
plt. show( )