代码
import matplotlib. pyplot as plt
import mpl_toolkits. axisartist as AA
from mpl_toolkits. axes_grid1 import host_subplot
% matplotlib inline
config = {
"font.family" : "serif" ,
"font.size" : 14 ,
"mathtext.fontset" : "stix" ,
"font.serif" : [ "Times New Roman" ] ,
"xtick.direction" : "in" ,
"ytick.direction" : "in" ,
}
plt. rcParams. update( config)
host = host_subplot( 111 , axes_class= AA. Axes)
par1 = host. twinx( )
par2 = host. twinx( )
par3 = host. twinx( )
host. axis[ "top" ] . set_visible( True )
offset = 0
new_fixed_axis = par1. get_grid_helper( ) . new_fixed_axis
par1. axis[ "right" ] = new_fixed_axis( loc= "right" , axes= par1, offset= ( offset, 0 ) )
par1. axis[ "right" ] . toggle( all = True )
offset = 50
new_fixed_axis = par2. get_grid_helper( ) . new_fixed_axis
par2. axis[ "right" ] = new_fixed_axis( loc= "right" , axes= par2, offset= ( offset, 0 ) )
par2. axis[ "right" ] . toggle( all = True )
offset = 110
new_fixed_axis = par3. get_grid_helper( ) . new_fixed_axis
par3. axis[ "right" ] = new_fixed_axis( loc= "right" , axes= par3, offset= ( offset, 0 ) )
par3. axis[ "right" ] . toggle( all = True )
host. set_xlabel( "Time (s)" , fontsize= config[ "font.size" ] + 2 )
host. text( - 22 , 0.35 , 'Normal stress, ' , color= 'c' , va= 'center' , rotation= 'vertical' , fontsize= config[ "font.size" ] + 2 )
host. text( - 22 , 0.74 , 'shear stress ' , color= 'm' , va= 'center' , rotation= 'vertical' , fontsize= config[ "font.size" ] + 2 )
host. text( - 22 , 1.01 , '(MPa)' , color= 'k' , va= 'center' , rotation= 'vertical' , fontsize= config[ "font.size" ] + 2 )
par1. set_ylabel( "Slip displacement (mm)" , fontsize= config[ "font.size" ] + 2 )
par2. set_ylabel( "Slip velocity (mm/s)" , fontsize= config[ "font.size" ] + 2 )
par3. set_ylabel( "Normal displacement (mm)" , fontsize= config[ "font.size" ] + 2 )
colors = [ "c" , "m" , "b" , "r" , "k" ]
p0 = host. plot(
data2. index,
data2[ "垂直応力(1)[MPa]" ] ,
"-" ,
linewidth= 1 ,
color= colors[ 0 ] ,
label= "Normal stress" ,
)
p0 = host. plot(
data2. index,
data2[ "せん断応力[MPa]" ] ,
"-" ,
linewidth= 1 ,
color= colors[ 1 ] ,
label= "Shear stress" ,
)
p1 = par1. plot(
data2. index,
data2[ "せん断変位[mm]" ] ,
linewidth= 1 ,
color= colors[ 2 ] ,
label= "shear displacement" ,
)
p2 = par2. plot(
data2. index,
data2[ "velocity[mm/s]" ] ,
linewidth= 1 ,
color= colors[ 3 ] ,
label= "shear velocity" ,
)
p3 = par3. plot(
data2. index,
data2[ "垂直全平均変位[mm]" ] ,
linewidth= 1 ,
color= colors[ 4 ] ,
label= "Normal displacement" ,
)
host. axis[ "left" ] . label. set_color( p0[ 0 ] . get_color( ) )
par1. axis[ "right" ] . label. set_color( p1[ 0 ] . get_color( ) )
par2. axis[ "right" ] . label. set_color( p2[ 0 ] . get_color( ) )
par3. axis[ "right" ] . label. set_color( p3[ 0 ] . get_color( ) )
host. set_xlim( 0 , 200 )
host. set_ylim( 0 , 1.2 )
par1. set_ylim( 0 , 18 )
par2. set_ylim( - 0.05 , 0.4 )
par3. set_ylim( 0 , 0.6 )
par3. plot( [ 45 , 45 ] , [ 0 , 20 ] , "k--" , alpha= 0.5 )
par3. plot( [ 120 , 120 ] , [ 0 , 20 ] , "k--" , alpha= 0.5 , label= 'Start for computing normal stifness' )
par3. plot( [ 148 , 148 ] , [ 0 , 20 ] , "k--" , alpha= 0.5 , label= 'End for computing normal stifness' )
par3. plot( [ 178 , 178 ] , [ 0 , 20 ] , "k--" , alpha= 0.5 , label= 'Start for computing shear dilation' )
par3. plot( [ 187 , 187 ] , [ 0 , 20 ] , "k--" , alpha= 0.5 , label= 'End for computing shear dilation' )
host. text( 3 , 1.12 ,
'${\\rm JRC=3.21}, \\sigma_{\\rm n}^{\\rm 0}=1 \\ {\\rm MPa}$' ,
fontsize= config[ "font.size" ] + 2 )
host. text( - 25 , 1.185 , '(a)' , fontsize= config[ "font.size" ] + 2 , fontweight= 'bold' )
plt. show( )
成品图