https://www.cnblogs.com/darkknightzh/p/6117528.html

https://blog.csdn.net/qq_34337272/article/details/79555544

1.设置栅格
(1)使用pyplot api命令

打开栅格:plt.grid(true)

设置栅格格式:plt.grid(color='r', linestyle='--', linewidth=1,alpha=0.3)

 

(2)使用axes类面向对象命令

#同时设置两坐标轴上的栅格线

ax.grid(color='r', linestyle='--', linewidth=1,alpha=0.3)  

#设置X坐标轴上(垂直方向)的栅格线

ax.xaxis.grid(color='r', linestyle='--', linewidth=1,alpha=0.3)

#设置Y坐标轴上(水平方向)的栅格线

ax.yaxis.grid(color='r', linestyle='--', linewidth=1,alpha=0.3)

2.设置axes脊柱(坐标系)
 

(1)去掉脊柱(坐标系)

ax.spines['top'].set_visible(False) #去掉上边框

ax.spines['bottom'].set_visible(False) #去掉下边框

ax.spines['left'].set_visible(False) #去掉左边框

ax.spines['right'].set_visible(False) #去掉右边框

 

(2)移动脊柱

ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))

 

(3)设置边框线颜色

ax = plt.gca() # 获取当前的axes

ax.spines['right'].set_color('blue')ax.spines['top'].set_color('none')

(4)设置边框线宽ax1.spines['left'].set_linewidth(5)

(5)设置边框线型ax.spines['left'].set_linestyle('--')

 

 

 

3.设置背景颜色
 

(1)设置figure背景颜色

 

facecolor:背景颜色  edgecolor:边框颜色

plt.figure(facecolor='blue',edgecolor='black')

fig=plt.gcf()
fig.set_facecolor('green')

 

 

(2)设置axes背景颜色

a = plt.axes([.65, .6, .2, .2], facecolor='k')  #pyplot api命令-黑色背景

或者

ax1=plt.gca()

ax1.patch.set_facecolor("gray")            #设置ax1区域背景颜色               

ax1.patch.set_alpha(0.5)                      #设置ax1区域背景颜色透明度       

 

(3)修改matplotlib默认参数

 

plt.rcParams['axes.facecolor']='red'

plt.rcParams['savefig.facecolor']='red'

'-'       solid line style
'--'      dashed line style
'-.'      dash-dot line style
':'       dotted line style
'.'       point marker
','       pixel marker
'o'       circle marker
'v'       triangle_down marker
'^'       triangle_up marker
'<'       triangle_left marker
'>'       triangle_right marker
'1'       tri_down marker
'2'       tri_up marker
'3'       tri_left marker
'4'       tri_right marker
's'       square marker
'p'       pentagon marker
'*'       star marker
'h'       hexagon1 marker
'H'       hexagon2 marker
'+'       plus marker
'x'       x marker
'D'       diamond marker
'd'       thin_diamond marker
'|'       vline marker
'_'       hline marker
View Code

相关文章:

  • 2021-11-14
  • 2021-07-03
  • 2021-04-08
  • 2022-12-23
  • 2021-10-24
  • 2022-01-21
猜你喜欢
  • 2021-12-09
相关资源
相似解决方案