def getFigureByXY(x,y):
ylabel='\nOutput, MBps'
fig = Figure(figsize=(16,6), dpi=120)
axis = fig.add_subplot(1, 1, 1)
axis.plot(x, y, color='#2b8ef9')
axis.fill_between(x,y, facecolor='#2b8ef9')
axis.grid(True)
axis.set_ylim(bottom=0)
axis.set_ylabel(ylabel)
# axis.set_xlabel('\n%s - %s' % (x[0],x[-1]))
axis.xaxis.set_major_formatter(dates.DateFormatter('%H:%M'))
axis.xaxis.set_major_locator(dates.HourLocator(byhour=range(0,24,1)))
fig.autofmt_xdate()
fig.set_facecolor('white')
return fig
python类HourLocator()的实例源码
def plot_date_axis(axes):
from matplotlib import dates
date_fmt = dates.DateFormatter('%d/%b')
hour_fmt = dates.DateFormatter('%H:%M')
# TODO: set xaxis minor interval dynamically
axes.xaxis.set_major_locator(dates.DayLocator(interval=1))
axes.xaxis.set_major_formatter(date_fmt)
# less than 5 days and interval of 3 is okay
axes.xaxis.set_minor_locator(dates.HourLocator(interval=4))
axes.xaxis.set_minor_formatter(hour_fmt)
axes.xaxis.set_tick_params(which='major', pad=15)
def format_ax(self, ax):
"""
Trying to assign reasonable parameters to the time axis.
Parameters
----------
ax:
"""
# TODO: room for improvement
ax.xaxis.set_major_locator(mdates.DayLocator(interval=1))
ax.xaxis.set_major_formatter(self.fmt)
locator = mdates.HourLocator(interval=4)
locator.MAXTICKS = 5000
ax.xaxis.set_minor_locator(locator)
datemin = pd.Timestamp.utcnow()
ax.set_xlim(datemin)
ax.grid(True)
def setAxisScaleX(self, x_axis_bins):
"""The setAxisScaleX() method sets the bins for the X axis. Presently,
we assume a date-based axis."""
if self.verboseLogging:
self.logger.threaddebug(u"Constructing the bins for the X axis.")
if x_axis_bins == 'quarter-hourly':
plt.gca().xaxis.set_major_locator(mdate.HourLocator(interval=4))
plt.gca().xaxis.set_minor_locator(mdate.HourLocator(byhour=range(0, 24, 96)))
if x_axis_bins == 'half-hourly':
plt.gca().xaxis.set_major_locator(mdate.HourLocator(interval=4))
plt.gca().xaxis.set_minor_locator(mdate.HourLocator(byhour=range(0, 24, 48)))
elif x_axis_bins == 'hourly':
plt.gca().xaxis.set_major_locator(mdate.HourLocator(interval=4))
plt.gca().xaxis.set_minor_locator(mdate.HourLocator(byhour=range(0, 24, 24)))
elif x_axis_bins == 'hourly_4':
plt.gca().xaxis.set_major_locator(mdate.HourLocator(interval=4))
plt.gca().xaxis.set_minor_locator(mdate.HourLocator(byhour=range(0, 24, 8)))
elif x_axis_bins == 'hourly_8':
plt.gca().xaxis.set_major_locator(mdate.HourLocator(interval=4))
plt.gca().xaxis.set_minor_locator(mdate.HourLocator(byhour=range(0, 24, 4)))
elif x_axis_bins == 'hourly_12':
plt.gca().xaxis.set_major_locator(mdate.HourLocator(interval=4))
plt.gca().xaxis.set_minor_locator(mdate.HourLocator(byhour=range(0, 24, 2)))
elif x_axis_bins == 'daily':
plt.gca().xaxis.set_major_locator(mdate.DayLocator(interval=1))
plt.gca().xaxis.set_minor_locator(mdate.HourLocator(byhour=range(0, 24, 6)))
elif x_axis_bins == 'weekly':
plt.gca().xaxis.set_major_locator(mdate.DayLocator(interval=7))
plt.gca().xaxis.set_minor_locator(mdate.DayLocator(interval=1))
elif x_axis_bins == 'monthly':
plt.gca().xaxis.set_major_locator(mdate.MonthLocator(interval=1))
plt.gca().xaxis.set_minor_locator(mdate.DayLocator(interval=1))
elif x_axis_bins == 'yearly':
plt.gca().xaxis.set_major_locator(mdate.YearLocator())
plt.gca().xaxis.set_minor_locator(mdate.MonthLocator(interval=12))