【Matplotlib】設置刻度(1)

刻度設置

參考文檔:

以xticks爲例:html

matplotlib.pyplot.xticks(*args, **kwargs)

獲取或者設置當前刻度位置和文本的 x-limits:api

# return locs, labels where locs is an array of tick locations and
# labels is an array of tick labels.
locs, labels = xticks()

# set the locations of the xticks
xticks( arange(6) )

# set the locations and labels of the xticks
xticks( arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') )

關鍵字 args ,若是有其餘的參數則是 Text 屬性。例如,旋轉長的文本標註。this

xticks( arange(12), calendar.month_name[1:13], rotation=17 )

參考文檔

Axis containers

matplotlib.axis.Axis對象負責刻度線、格網線、刻度標註和座標軸標註的繪製工做。你能夠設置y軸的左右刻度或者x軸的上下刻度。 Axis 也存儲了用於自動調整,移動和放縮的數據和視覺間隔;同時 LocatorFormatter 對象控制着刻度的位置以及以怎樣的字符串呈現。code

每個 Axis 對象包含一個 label 屬性以及主刻度和小刻度的列表。刻度是 XTickYTick 對象,其包含着實際線和文本元素,分別表明刻度和註釋。由於刻度是根據須要動態建立的,你應該經過獲取方法 get_major_ticks()get_minor_ticks()以獲取主刻度和小刻度的列表。儘管刻度包含了全部的元素,而且將會在下面代碼中涵蓋,Axis 方法包含了獲取方法以返回刻度線、刻度標註和刻度位置等等:orm

In [285]: axis = ax.xaxis

In [286]: axis.get_ticklocs()
Out[286]: array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.])

In [287]: axis.get_ticklabels()
Out[287]: <a list of 10 Text major ticklabel objects>

# note there are twice as many ticklines as labels because by
#  default there are tick lines at the top and bottom but only tick
#  labels below the xaxis; this can be customized
In [288]: axis.get_ticklines()
Out[288]: <a list of 20 Line2D ticklines objects>

# by default you get the major ticks back
In [291]: axis.get_ticklines()
Out[291]: <a list of 20 Line2D ticklines objects>

# but you can also ask for the minor ticks
In [292]: axis.get_ticklines(minor=True)
Out[292]: <a list of 0 Line2D ticklines objects>
相關文章
相關標籤/搜索