Python matplotlib.dates 模块,HourLocator() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用matplotlib.dates.HourLocator()

项目:trafficjuggler    作者:Pavel-Polyakov    | 项目源码 | 文件源码
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
项目:raiden    作者:raiden-network    | 项目源码 | 文件源码
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)
项目:catalyst    作者:enigmampc    | 项目源码 | 文件源码
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)
项目:matplotlib    作者:DaveL17    | 项目源码 | 文件源码
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))