1. 程式人生 > >Matplotlib命令與格式:tick_params引數設定

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')