import matplotlib as mpl
import matplotlib. pyplot as plt
import matplotlib. ticker as ticker
import numpy as np
import pandas as pd
plt. rcParams[ 'font.sans-serif' ] = [ 'SimHei' ]
plt. rcParams[ 'axes.unicode_minus' ] = False
print ( "Done" )
Done
ex1 = pd. read_csv( './data/layout_ex1.csv' )
ex1. head( )
Time Temperature 0 1981-01 17.712903 1 1981-02 17.678571 2 1981-03 13.500000 3 1981-04 12.356667 4 1981-05 9.490323
fig, axs = plt. subplots( 2 , 5 , figsize= ( 20 , 5 ) , sharex= True , sharey= True )
fig. suptitle( '墨尔本1981年至1990年月温度曲线' , size= 20 )
index = 0
for i in range ( 2 ) :
for j in range ( 5 ) :
axs[ i] [ j] . plot( np. arange( 1 , 13 ) , ex1[ 'Temperature' ] . values[ index* 12 : ( index* 12 + 12 ) ] , 'o-' )
axs[ i] [ j] . set_title( '%s年' % ex1[ 'Time' ] . values[ index] [ : 4 ] )
axs[ i] [ j] . xaxis. set_major_locator( ticker. MultipleLocator( 1 ) )
axs[ i] [ j] . yaxis. set_major_locator( ticker. MultipleLocator( 5 ) )
if j== 0 :
axs[ i] [ j] . set_ylabel( '气温' )
index += 1
fig. tight_layout( )
data_x, data_y = np. random. randn( 2 , 150 )
fig = plt. figure( figsize = ( 6 , 6 ) )
fig. tight_layout( )
gs = fig. add_gridspec( 2 , 2 , width_ratios = [ 5 , 1 ] , height_ratios = [ 1 , 5 ] ,
wspace = 0.05 , hspace = 0.05 )
ax = fig. add_subplot( gs[ 1 , 0 ] )
ax_histx = fig. add_subplot( gs[ 0 , 0 ] , sharex = ax)
ax_histy = fig. add_subplot( gs[ 1 , 1 ] , sharey = ax)
ax. scatter( data_x, data_y)
ax_histx. hist( data_x, 10 , rwidth = 0.9 )
ax_histy. hist( data_y, 10 , rwidth = 0.9 , orientation = 'horizontal' )
ax. grid( True )
ax. set_xlabel( 'my_data_x' , fontsize = 8 )
for label in ax. xaxis. get_ticklabels( ) :
label. set_size( 8 )
ax. set_ylabel( 'my_data_y' , fontsize = 8 )
for label in ax. yaxis. get_ticklabels( ) :
label. set_size( 8 )
ax_histx. axis( 'off' )
ax_histy. axis( 'off' )
plt. show( )