堆积条形图

时间:2019-07-22 06:53:34

标签: plotly plotly-dash

This is what I get在以散点图创建堆积的条形图时遇到问题。

当我尝试时,该图看起来像是堆积了一年中的最后一个变量,只是该变量被认为是前进的。

df
    Year    Month   Value
0   2000    Jan    1
1   2000    Feb    2
2   2001    Jan    3
3   2001    Feb    4


import plotly.plotly as py
import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
import pandas as pd
import numpy as np

data = [[2000, 2000, 2000, 2001, 2001, 2001, 2002, 2002, 2002],
        ['Jan', 'Feb', 'Mar', 'Jan', 'Feb', 'Mar', 'Jan', 'Feb', 'Mar'],
        [1, 2, 3, 4, 5, 6, 7, 8, 9]]

rows = zip(data[0], data[1], data[2])
headers = ['Year', 'Month', 'Value']
df = pd.DataFrame(rows, columns=headers)
df
data = [
    go.Bar(
        x=df['Year'].unique(), 
        y=df['Month']

    ),
    go.Bar(
        x=df['Year'].unique(),
        y=df['Value']     
    )
]
layout = go.Layout(
    barmode='stack',
    title='Stacked Bar with Pandas'

)


fig = go.Figure(data=data, layout=layout)
fig.show()



我需要以x轴为Year,以y轴为值,并基于月份堆叠x轴的图。

Need Graph like the below

0 个答案:

没有答案