Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.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
Python 设置Plotly条形图x轴的对齐方式_Python_Plotly_Plotly Python - Fatal编程技术网

Python 设置Plotly条形图x轴的对齐方式

Python 设置Plotly条形图x轴的对齐方式,python,plotly,plotly-python,Python,Plotly,Plotly Python,嗨,我正在尝试改变我的条形图开始和停止的位置。我的目标是要有一个跨越整个月的酒吧。现在我的代码是: cumulative = go.Bar(y=self.gb[self.y_column], x=self.gb.index, name='Cumulative', hoverinfo='x+y', h

嗨,我正在尝试改变我的条形图开始和停止的位置。我的目标是要有一个跨越整个月的酒吧。现在我的代码是:

    cumulative = go.Bar(y=self.gb[self.y_column],
                        x=self.gb.index,
                        name='Cumulative',
                        hoverinfo='x+y',
                        hovertemplate="Month: %{x} <br>Cumulative Tank " + self.units + ": %{y}",
                        opacity=0.6,
                        marker=dict(color='rgb(158,202,225)',
                                    line=dict(color='rgb(8,48,107)',
                                              width=1.5,
                                              ),
                                    )
                        )
cumulative=go.Bar(y=self.gb[self.y\u列],
x=self.gb.index,
name='Cumulative',
hoverinfo='x+y',
hovertemplate=“月:%{x}
累计油箱“+self.units+”:%{y}”, 不透明度=0.6, marker=dict(color='rgb(15820225)', line=dict(color='rgb(8,48107)', 宽度=1.5, ), ) )
我的输出是:

我目前在月底设置了xtick。如果我可以使这些条与xtick右对齐,我可以使用自定义条宽度使其到达月底。我不认为我可以计算月中旬,因为在31天的月份里,我要么有一天的间隔,要么超过一天。任何帮助都将不胜感激


我在论坛上就这个问题发表了一篇生动的帖子:

这不是一个解决方案,而是一个我很满意的解决方案

所以我决定通过使用填充线图来实现一种变通方法。以下是代码,一个用于计算每月累积值和绘图填充区域散布对象的辅助函数:

def cumulative_df(df, date_term, y_term, v_print):
    v_print('Making the Monthly Sum DF')
    df = df[[date_term, y_term]]
    df = df.set_index(date_term)
    gb = df.groupby(pd.Grouper(freq="M")).sum()

    starts = []
    for index, row in gb.iterrows():
        new_start = index - pd.offsets.MonthBegin(1, normalize=True)
        starts.append([new_start, row.values[0]])

    starts_df = pd.DataFrame(starts, columns=[date_term, y_term])
    starts_df = starts_df.set_index(date_term)
    gb = gb.append(starts_df, sort=False)
    gb.sort_values(date_term, inplace=True)
    return gb
还有一个生动的呼吁:

        cumulative = [go.Scatter(y=self.gb[self.y_column],
                                x=self.gb.index,
                                name='Cumulative',
                                hoverinfo='x+y',
                                hovertemplate="Month: %{x} <br>Cumulative Meter " + self.units + ": %{y}",
                                fill='tozeroy',
                                fillcolor=self.fill_color,
                                line={'color': self.cum_line_color,}
                                )]

        scatters = cumulative + scatters
cumulative=[go.Scatter(y=self.gb[self.y\u column],
x=self.gb.index,
name='Cumulative',
hoverinfo='x+y',
hovertemplate=“月:%{x}
累计米数”+self.units+“:%{y}”, 填充class='tozeroy', fillcolor=self.fill\u color, line={'color':self.cum_line_color,} )] 散射=累积+散射
以下是输出:

这不是一个解决方案,而是一个我很满意的解决方案

所以我决定通过使用填充线图来实现一种变通方法。以下是代码,一个用于计算每月累积值和绘图填充区域散布对象的辅助函数:

def cumulative_df(df, date_term, y_term, v_print):
    v_print('Making the Monthly Sum DF')
    df = df[[date_term, y_term]]
    df = df.set_index(date_term)
    gb = df.groupby(pd.Grouper(freq="M")).sum()

    starts = []
    for index, row in gb.iterrows():
        new_start = index - pd.offsets.MonthBegin(1, normalize=True)
        starts.append([new_start, row.values[0]])

    starts_df = pd.DataFrame(starts, columns=[date_term, y_term])
    starts_df = starts_df.set_index(date_term)
    gb = gb.append(starts_df, sort=False)
    gb.sort_values(date_term, inplace=True)
    return gb
还有一个生动的呼吁:

        cumulative = [go.Scatter(y=self.gb[self.y_column],
                                x=self.gb.index,
                                name='Cumulative',
                                hoverinfo='x+y',
                                hovertemplate="Month: %{x} <br>Cumulative Meter " + self.units + ": %{y}",
                                fill='tozeroy',
                                fillcolor=self.fill_color,
                                line={'color': self.cum_line_color,}
                                )]

        scatters = cumulative + scatters
cumulative=[go.Scatter(y=self.gb[self.y\u column],
x=self.gb.index,
name='Cumulative',
hoverinfo='x+y',
hovertemplate=“月:%{x}
累计米数”+self.units+“:%{y}”, 填充class='tozeroy', fillcolor=self.fill\u color, line={'color':self.cum_line_color,} )] 散射=累积+散射
以下是输出: