文章目录 1、导入 2、定义Font及Style 3、设置图像大小及坐标刻度 4、数据准备 5、自定义draw 6、其他设置 7、效果图
1、导入
import matplotlib
import matplotlib. pyplot as plt
from matplotlib. backends. backend_pdf import PdfPages
import numpy as np
import pandas as pd
% matplotlib inline
2、定义Font及Style
plt. style. use( "seaborn-v0_8-whitegrid" )
palette = plt. get_cmap( 'Set1' )
font1 = { 'family' : 'Times New Roman' ,
'weight' : 'normal' ,
'size' : 60 ,
}
font2 = { 'family' : 'Times New Roman' ,
'weight' : 'normal' ,
'size' : 38 ,
}
3、设置图像大小及坐标刻度
fig= plt. figure( figsize= ( 18 , 12.6 ) )
my_x_ticks= np. arange( 10 , 70 , 10 )
lab = [ r'10' , r'20' , r'30' , r'40' , r'50' , r'60' ]
plt. xticks( ticks= my_x_ticks, labels= lab)
plt. yticks( )
4、数据准备
iters= [ 10 , 20 , 30 , 40 , 50 , 60 ] y1 = [ 79 , 77 , 74 , 76 , 73 , 71 ] y2 = [ 68 , 66 , 65 , 64 , 61 , 62 ] y3 = [ 48 , 47 , 48 , 45 , 44 , 42 ] y4 = [ 58 , 56 , 55 , 53 , 54 , 50 ] y5 = [ 39 , 38 , 37 , 36 , 34 , 30 ]
std1 = [ 1.47 , 1.46 , 2.01 , 1.11 , 2.07 , 1.95 ]
std2 = [ 2.78 , 2.77 , 2.34 , 2.28 , 2.34 , 2.89 ]
std3 = [ 1.5 , 2.7 , 2.0 , 1.7 , 2.0 , 2.3 ]
std4 = [ 2.64 , 3.64 , 1.69 , 3.32 , 2.29 , 1.97 ]
std5 = [ 3.00 , 2.49 , 3.40 , 3.10 , 2.47 , 3.46 ] r11 = list ( map ( lambda x: x[ 0 ] - x[ 1 ] , zip ( y1, std1) ) )
r12 = list ( map ( lambda x: x[ 0 ] + x[ 1 ] , zip ( y1, std1) ) ) r21 = list ( map ( lambda x: x[ 0 ] - x[ 1 ] , zip ( y2, std2) ) )
r22 = list ( map ( lambda x: x[ 0 ] + x[ 1 ] , zip ( y2, std2) ) ) r31 = list ( map ( lambda x: x[ 0 ] - x[ 1 ] , zip ( y3, std3) ) )
r32 = list ( map ( lambda x: x[ 0 ] + x[ 1 ] , zip ( y3, std3) ) ) r41 = list ( map ( lambda x: x[ 0 ] - x[ 1 ] , zip ( y4, std4) ) )
r42 = list ( map ( lambda x: x[ 0 ] + x[ 1 ] , zip ( y4, std4) ) ) r51 = list ( map ( lambda x: x[ 0 ] - x[ 1 ] , zip ( y5, std5) ) )
r52 = list ( map ( lambda x: x[ 0 ] + x[ 1 ] , zip ( y5, std5) ) )
5、自定义draw
def draw_line ( name_of_alg, color_index, y, r1, r2, marker) : if isinstance ( color_index, str ) : color = color_indexelse : color= palette( color_index) plt. plot( iters, y, color= color, label= name_of_alg, linewidth= 8 , marker= marker, markeredgecolor= color, markersize= '24' , markeredgewidth= 4 , markerfacecolor= 'none' ) plt. fill_between( iters, r1, r2, color= color, alpha= 0.2 ) draw_line( "A" , 4 , y1, r11, r12, 'D' )
draw_line( "B" , 2 , y2, r21, r22, 's' )
draw_line( "C" , 1 , y3, r31, r32, 'o' )
draw_line( "D" , 3 , y4, r41, r42, 'v' )
draw_line( "E" , 7 , y5, r51, r52, 'p' )
6、其他设置
plt. xticks( fontsize= 50 )
plt. yticks( fontsize= 50 )
plt. xlabel( 'X(%)' , font1)
plt. ylabel( 'Y(%)' , font1)
plt. legend( loc= 'lower left' , prop= font2, frameon= True , fancybox= True , framealpha= 0.5 )
plt. title( "EXAMPLE" , fontsize= 60 )
plt. savefig( './EXAMPLE.pdf' )
plt. show( )
7、效果图