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

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

项目:trading-stock-thailand    作者:adminho    | 项目源码 | 文件源码
def plotCandlestick(symbol, dates, title="Selected data"):  
    quotes = loadStockQuotes(symbol, dates)     

    mondays = WeekdayLocator(MONDAY)        # major ticks on the mondays
    alldays = DayLocator()                  # minor ticks on the days
    weekFormatter = DateFormatter('%b %d')  # e.g., Jan 12
    dayFormatter = DateFormatter('%d')      # e.g., 12

    fig, ax = plt.subplots()
    fig.subplots_adjust(bottom=0.2)
    ax.xaxis.set_major_locator(mondays)
    ax.xaxis.set_minor_locator(alldays)
    ax.xaxis.set_major_formatter(weekFormatter)
    #ax.xaxis.set_minor_formatter(dayFormatter)

    #plot_day_summary(ax, quotes, ticksize=3)
    candlestick_ohlc(ax, quotes, width=0.6)

    ax.xaxis_date()
    ax.autoscale_view()
    ax.set_title(title)
    plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')

    plt.show()
项目:trading-stock-thailand    作者:adminho    | 项目源码 | 文件源码
def plotCandlestick(symbol, startdate, enddate, title="Selected data"): 
    quotes = loadStockQuotes(symbol, startdate, enddate)        
    print(quotes)
    mondays = WeekdayLocator(MONDAY)        # major ticks on the mondays
    alldays = DayLocator()              # minor ticks on the days
    weekFormatter = DateFormatter('%b %d')  # e.g., Jan 12
#   dayFormatter = DateFormatter('%d')    # e.g., 12

    fig, ax = plt.subplots()
    fig.subplots_adjust(bottom=0.2)
    ax.xaxis.set_major_locator(mondays)
    ax.xaxis.set_minor_locator(alldays)
    ax.xaxis.set_major_formatter(weekFormatter)
    #ax.xaxis.set_minor_formatter(dayFormatter)

    #plot_day_summary(ax, quotes, ticksize=3)
    candlestick_ohlc(ax, quotes, width=0.6)

    ax.xaxis_date()
    ax.autoscale_view()
    ax.set_title(title)
    plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')

    plt.show()
项目:trading-stock-thailand    作者:adminho    | 项目源码 | 文件源码
def plotCandlestick(symbol, start_index, end_index, title="Selected data"):
    dates = pd.date_range(start_index, end_index)   
    quotes = utl.loadStockQuotes(symbol, dates)     

    mondays = WeekdayLocator(MONDAY)        # major ticks on the mondays
    alldays = DayLocator()                  # minor ticks on the days
    weekFormatter = DateFormatter('%b %d')  # e.g., Jan 12
    dayFormatter = DateFormatter('%d')      # e.g., 12

    fig, ax = plt.subplots()
    fig.subplots_adjust(bottom=0.2)
    ax.xaxis.set_major_locator(mondays)
    ax.xaxis.set_minor_locator(alldays)
    ax.xaxis.set_major_formatter(weekFormatter)
    #ax.xaxis.set_minor_formatter(dayFormatter)

    #plot_day_summary(ax, quotes, ticksize=3)
    candlestick_ohlc(ax, quotes, width=0.6)

    ax.xaxis_date()
    ax.autoscale_view()
    plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')

    plt.show()
项目:themarketingtechnologist    作者:thomhopmans    | 项目源码 | 文件源码
def apply_date_formatting_to_axis(ax):
        """ Format x-axis of input plot to a readable date format """
        ax.xaxis.set_minor_locator(dates.WeekdayLocator(byweekday=(0), interval=1))
        ax.xaxis.set_minor_formatter(dates.DateFormatter('%d\n%a'))
        ax.xaxis.grid(True, which="minor")
        ax.yaxis.grid()
        ax.xaxis.set_major_locator(dates.MonthLocator())
        ax.xaxis.set_major_formatter(dates.DateFormatter('\n\n\n%b\n%Y'))
        return ax
项目:AirTicketPredicting    作者:junlulocky    | 项目源码 | 文件源码
def getDatasForOneRouteForOneDepartureDate(route, departureDate):
    X = getOneRouteData(datas, route)
    minDeparture = np.amin(X[:,8])
    maxDeparture = np.amax(X[:,8])
    print minDeparture
    print maxDeparture

    # get specific departure date datas
    X = X[np.where(X[:, 8]==departureDate)[0], :]

    # get the x values
    xaxis = X[:,9] # observed date state
    print xaxis
    xaxis = departureDate-1-xaxis
    print xaxis

    tmp = xaxis
    startdate = "20151109"
    xaxis = [pd.to_datetime(startdate) + pd.DateOffset(days=state) for state in tmp]
    print xaxis

    # get the y values
    yaxis = X[:,12]


    # every monday
    mondays = WeekdayLocator(MONDAY)

    # every 3rd month
    months = MonthLocator(range(1, 13), bymonthday=1, interval=01)
    days = WeekdayLocator(byweekday=1, interval=2)
    monthsFmt = DateFormatter("%b. %d, %Y")

    fig, ax = plt.subplots()
    ax.plot_date(xaxis, yaxis, 'r--')
    ax.plot_date(xaxis, yaxis, 'bo')
    ax.xaxis.set_major_locator(days)
    ax.xaxis.set_major_formatter(monthsFmt)
    #ax.xaxis.set_minor_locator(mondays)
    ax.autoscale_view()
    #ax.xaxis.grid(False, 'major')
    #ax.xaxis.grid(True, 'minor')
    ax.grid(True)
    plt.xlabel('Date')
    plt.ylabel('Price in Euro')

    fig.autofmt_xdate()
    plt.show()

    """
    # plot
    line1, = plt.plot(xaxis, yaxis, 'r--')
    line2, = plt.plot(xaxis, yaxis, 'bo')
    #plt.legend([line2], ["Price"])
    plt.xlabel('States')
    plt.ylabel('Price in Euro')
    plt.show()
    """