import numpy as np
c= np. random. randn( 0 , 100 , 10 )
y= np. sort( c)
y
c. sort( )
import matplotlib. pyplot as plt
height= [ 170 , 165 , 124 , 180 ]
weight= [ 80 , 60 , 45 , 85 ]
plt. scatter( height, weight)
plt. show( )
n= 1000
x= np. random. randn( n)
y1= np. random. randn( n)
plt. scatter( x, y1)
plt. show( )
plt. scatter( x, y1, s= 100 , c= 'r' , marker= '<' , alpha= 0.5 )
plt. show( )
x= np. linspace( - 10 , 10 , 100 )
y= x** 2
plt. plot( x, y)
plt. show( )
import matplotlib. dates as mdate
N= 5
y= [ 20 , 10 , 30 , 25 , 15 ]
index= np. arange( N)
p1= plt. bar( left= index, height= y, color= 'b' , width= 0.8 )
p2= plt. bar( left= 0 , bottom= index, height= y, orientation= 'horizontal' )
p3= plt. barh( left= 0 , bottom= index, height= y)
plt. show( )
salesBJ= [ 3 , 5 , 6 , 7 ]
salesSH= [ 6 , 2 , 1 , 3 ]
bar_width= 0.3
plt. bar( index, salesBJ, bar_width, color= 'b' )
plt. bar( index+ bar_width, salesSH, bar_width, color= 'r' )
plt. show( )
plt. bar( index, salesSH, bar_width, color= 'r' , bottom= salesSH)
mu= 100
sigma= 20
x= mu+ sigma* np. random. randn( 2000 )
plt. hist( x, bins= 10 , color= 'green' , normal= True )
plt. show( )
x= np. random. randn( 100 ) + 2
y= np. random. randn( 100 ) + 3
plt. hist2d( x, y, bins= 10 )
labels= 'A' , 'B' , 'C' , 'D'
fracs= [ 15 , 35 , 40 , 10 ]
explode= [ 0 , 0 , 0.5 , 0 ]
plt. axes( aspect= 1 )
plt. pie( x= fracs, labels= labels, explode= explode, autopct= '%.0f%%' )
plt. show( )
np. random. seed( 100 )
data= np. random. normal( size= 1000 , loc= 0 , scale= 1 )
plt. boxplot( data, sys= 'o' , whis= 1.5 )
from pylab import *
x= arange( 0 , 10 , 1 )
y= randn( len ( x) )
plot( x, y)
title( 'pylab' )
show( )
a= np. arange( 0 , 10 , 1 )
b= np. random. randn( len ( a) )
plt. plot( a, b)
plt. title( 'pyplot' )
x= np. arange( 1 , 100 )
fig= plt. figure( )
ax1= fig. add_subplot( 221 )
ax1. plot( x, x)
ax2= fig. add_subplot( 222 )
ax2. plot( x, - x)
plt. subplot( 221 )
plt. plot( x, x)
plt. subplot( 2 , 2 , 2 )
plt. plot( x, - x)
fig1= plt. figure( )
ax1= fig1. add_subplot( 111 )
ax1. plot( [ 1 , 2 , 3 ] , [ 3 , 2 , 1 ] )
fig2= plt. figure( )
ax2= fig2. add_subplot( 111 )
ax2. plot( [ 1 , 3 , 4 ] , [ 4 , 3 , 2 ] )
y= np. arange( 1 , 5 )
plt. plot( y, y* 2 )
plt. grid( True )
plt. grid( color= 'r' , linestyle= '-' )
plt. plot( x, x* 2 , labels= 'normal' )
plt. plot( x, x* 3 , labels= 'fast' )
plt. plot( x, x* 4 , labels= 'faster' )
plt. legend( loc= 1 , ncol= 3 )
fig= plt. figure( )
ax= fig1. add_subplot( 111 )
l, = plt. plot( x, x)
ax. legend( [ 'ax.legend' ] )
plt. axes( [ 10 , 10 , 0 , 100 ] )
plt. xlim( [ - 1 , 10 ] )
ax= plt. plot( x, x)
ax. locator_paramts( nbins= 10 )
ax. locator_paramts( 'x' , nbins= 10 )
plt. locator_params( 'x' , nbins= 5 )
import matplotlib as mpl
import datetime
fig= plt. figure( )
start= datetime. datetime( 2019 , 1 , 1 )
stop= datetime. datetime( 2020 , 1 , 1 )
delta= datetime. timedelta( days= 1 )
dates= mpl. dates. drange( start, stop, delta)
y= np. random. randn( len ( dates) )
ax= plt. gca( )
ax. plot_date( dates, y, linstyle= '-' )
date_format= mpl. dates. DateFormatter( '%y-%m-%d' )
ax. xaix. set_major_formatter( date_format)
x= np. random. randn( 2 , 20 , 1 )
y1= x** 2
y2= np. log( x)
plt. plot( x, y1)
plt. twinx( )
plt. twiny( )
plt. plot( x, y2)
fig1= plt. figure( )
ax1= fig1. add_subplot( 111 )
ax1. plot( x, y1)
ax1. set_ylabel( 'Y1' )
ax2= ax1. twinx( )
ax2. plot( x, y2)
ax2. set_ylabel( 'Y2' )
ax1. set_xlabel( 'compare Y1 and Y2' )