Python之matplotlib學習(三)

例子11-1:橫座標時間的處理python

from matplotlib.dates import datestr2num,DateFormatter

import matplotlib.dates as dates

fig,ax=plt.subplots()
formatter = DateFormatter('%H')
#設置時間間隔
ax.xaxis.set_major_locator(dates.HourLocator(byhour=range(24), interval=4))
ax.xaxis.set_major_formatter(formatter)
ax.plot_date(datestr2num(time_list),iops_list,'-',label='iops')

 

輸出結果:orm

例子11-2:縱座標處理blog

原圖:ip

 

從圖上看縱座標區間過大,不利用查看。ci

改爲200爲步長:文檔

import matplotlib.ticker as tk

ax.yaxis.set_major_locator(tk.MultipleLocator(200)) 

 

輸出結果:it

例子11-3:縱座標處理——按照分鐘進行間隔io

以下是原始輸出的圖form

時間軸每5分鐘一次,過於太密,想改爲以下效果:class

按照分鐘級別進行彙總,代碼修改的地方以下:

import matplotlib.dates as dates
ax.xaxis.set_major_locator(dates.MinuteLocator(byminute=range(60), interval=10))

>>> import matplotlib.dates as dates
>>> help(dates)

#查看幫助文檔
Here are all the date tickers:
    
        * :class:`MinuteLocator`: locate minutes
    
        * :class:`HourLocator`: locate hours
    
        * :class:`DayLocator`: locate specifed days of the month
    
        * :class:`WeekdayLocator`: Locate days of the week, eg MO, TU
    
        * :class:`MonthLocator`: locate months, eg 7 for july
    
        * :class:`YearLocator`: locate years that are multiples of base
    

     |  ----------------------------------------------------------------------
     |  Data and other attributes inherited from DateLocator:
     |  
     |  hms0d = {'byhour': 0, 'byminute': 0, 'bysecond': 0}
相關文章
相關標籤/搜索