Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pandas 如何在bokeh中固定日期时间轴刻度?_Pandas_Dataframe_Time Series_Bokeh_Ticker - Fatal编程技术网

Pandas 如何在bokeh中固定日期时间轴刻度?

Pandas 如何在bokeh中固定日期时间轴刻度?,pandas,dataframe,time-series,bokeh,ticker,Pandas,Dataframe,Time Series,Bokeh,Ticker,我试图在timeseries折线图中为我的每个数据点显示一个勾号,在该折线图中,timeseries可以根据用户的选择以不同的速率重新采样 分-时-日-月 如果用户选择小时,我希望每个刻度为一小时,如果用户选择天,则为一天,依此类推 然后,我希望这些刻度保持固定,这样当我缩放图表时,bokeh不会在其间创建新的分小时、分天刻度 我曾尝试在x轴上使用所需的刻度,但当我缩放图表时,我相信图表中的刻度数保持不变,因此会使我的刻度低于我指定的时间刻度 首先,我根据平均值或总和对数据重新采样,具体取决于时

我试图在timeseries折线图中为我的每个数据点显示一个勾号,在该折线图中,timeseries可以根据用户的选择以不同的速率重新采样

分-时-日-月

如果用户选择小时,我希望每个刻度为一小时,如果用户选择天,则为一天,依此类推

然后,我希望这些刻度保持固定,这样当我缩放图表时,bokeh不会在其间创建新的分小时、分天刻度

我曾尝试在x轴上使用所需的刻度,但当我缩放图表时,我相信图表中的刻度数保持不变,因此会使我的刻度低于我指定的时间刻度

首先,我根据平均值或总和对数据重新采样,具体取决于时间尺度

   # Read ##########################################################################
    # Resample to Hour by average
    if resample_rate == 'T':
        pass
    else:
        df = df.resample('H').mean()
        if resample_rate == 'H':
            pass
        else:
            df = df.resample('{}'.format(resample_rate)).sum()
然后我尝试绘制我的数据。Timeseries格式化工作正常,但我无法使x轴按我所希望的方式运行

    energy_plot = figure(plot_width=1400,
                         plot_height=600,
                         title="Timeseries DC Power",
                         x_axis_type='datetime')

    # Label Axes
    energy_plot.xaxis[0].axis_label = 'Months'
    energy_plot.yaxis[0].axis_label = 'DC Power [W]'

    # background color
    energy_plot.background_fill_color = "white"
    energy_plot.background_fill_alpha = 0.5

    # grid lines
    energy_plot.xgrid.grid_line_color = None
    energy_plot.ygrid.grid_line_color = None

    colors = itertools.cycle(Dark2_5)

    # plot all dc power
    for column, label, c in zip(string_db_list, labels, colors):
        energy_plot.line(df.index,
                     df['{}'.format(column)],
                     line_width=4,
                     alpha=0.8,
                     color=c,
                     visible=False,
                     legend="{}".format(label))


    # clicking on the legend hides selection
    energy_plot.legend.click_policy = "hide"

    # Format the xaxis as datetime ticks
    try:
        energy_plot.xaxis.formatter = DatetimeTickFormatter(
            hours=["%d %B %Y"],
            days=["%d %B %Y"],
            months=["%d %B %Y"],
            years=["%d %B %Y"],)
        energy_plot.xaxis.major_label_orientation = 3.14 / 4
        energy_plot.xaxis[0].num_minor_ticks = 0
        energy_plot.xaxis[0].desired_num_ticks = df.index
    except:
        pass
当图表初始化时,刻度的数量看起来不错,尽管放大时它不会保持不变


为什么在
try…中设置的是格式块以外的块
?这看起来更像一个分类轴(即显示日期字符串,而不是实时日期值)。如果没有一个完整的最小复制器,很难说更多。您是否尝试过手动定义x轴的标记器?为什么在
try…中设置的是格式,除了块之外?这看起来更像一个分类轴(即显示日期字符串,而不是实时日期值)。如果没有一个完整的最小复制器,很难说更多。您是否尝试过手动定义x轴的标记器?