Matplotlib:tick_params參數設置


1.tick_params語法

參數:
axis : {‘x’, ‘y’, ‘both’} Axis on which to operate; default is ‘both’.
reset : bool If True, set all parameters to defaults before processing other keyword arguments. Default is False.
which : {‘major’, ‘minor’, ‘both’} Default is ‘major’; apply arguments to which ticks.
direction : {‘in’, ‘out’, ‘inout’} Puts ticks inside the axes, outside the axes, or both.
length : float Tick length in points.
width : float Tick width in points.
color : color Tick color; accepts any mpl color spec.
pad : float Distance in points between tick and label.
labelsize : float or str Tick label font size in points or as a string (e.g., ‘large’).
labelcolor : color Tick label color; mpl color spec.
colors : color Changes the tick color and the label color to the same value: mpl color spec.
zorder : float Tick and label zorder.
bottom, top, left, right : bool or {‘on’, ‘off’} controls whether to draw the respective ticks.
labelbottom, labeltop, labelleft, labelright : bool or {‘on’, ‘off’} controls whether to draw the respective tick labels.
labelrotation : float Tick label rotation

2.tick_params例子:

(1)參數axis的值為'x'、'y'、'both',分別代表設置X軸、Y軸以及同時設置,默認值為'both'。
ax1.tick_params(axis='x',width=2,colors='gold')
ax2.tick_params(axis='y',width=2,colors='gold')
ax3.tick_params(axis='both',width=2,colors='gold')

(2)參數which的值為 'major'、'minor'、'both',分別代表設置主刻度線、副刻度線以及同時設置,默認值為'major'
ax1.tick_params(which='major',width=2,colors='gold')
ax2.tick_params(which='minor',width=2,colors='gold')
ax3.tick_params(which='both',width=2,colors='gold')

(3)參數direction的值為'in'、'out'、'inout',分別代表刻度線顯示在繪圖區內側、外側以及同時顯示
ax1.tick_params(direction='in',width=2,length=4,colors='gold')
ax2.tick_params(direction='out',width=2,length=4,colors='gold')
ax3.tick_params(direction='inout',width=2,length=4,colors='gold')

(4)length和width
參數length和width分別用於設置刻度線的長度和寬度
ax2.tick_params(width=4,colors='gold')
ax3.tick_params(length=10,colors='gold')

(5)參數pad用於設置刻度線與標簽間的距離
ax2.tick_params(pad=1,colors='gold')
ax3.tick_params(pad=10,colors='gold')

(6)參數color、labelcolor、colors分別用於設置刻度線的顏色、刻度線標簽的顏色以及同時設置刻度線及標簽顏色
ax1.tick_params(width=4,color='gold')
ax2.tick_params(width=4,labelcolor='gold')
ax3.tick_params(width=4,colors='gold')

(7)參數labelsize用於設置刻度線標簽的字體大小
ax1.tick_params(labelsize='medium')
ax2.tick_params(labelsize='large')
ax3.tick_params(labelsize=15)

(8)參數bottom, top, left, right的值為布爾值,分別代表設置繪圖區四個邊框線上的的刻度線是否顯示
ax1.tick_params(bottom=False,top=True,width=4,colors='gold')
ax2.tick_params(left=False,right=True,width=4,colors='gold')
ax3.tick_params(top=True,right=True,width=4,colors='gold')

(9)參數labelbottom, labeltop, labelleft, labelright的值為布爾值,分別代表設置繪圖區四個邊框線上的刻度線標簽是否顯示
ax1.tick_params(labelbottom=False,labeltop=True,width=4,colors='gold')
ax2.tick_params(labelleft=False,labelright=True,width=4,colors='gold')
ax3.tick_params(labeltop=True,labelright=True,width=4,colors='gold')

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM