I want to create stacked bar chart with x-axis as Year and stacked the year with the month and projected the y with Value
I have an issue in creating the stacked bar chart. I 'll share the below code
Blockquote
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(), # assign x as the dataframe column 'x'
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()
Blockquote