Getting used to using Python’s implementation of Plotly after previously using a Google Charts wrapper for my data visualizations. I’m trying to create a stacked bar chart using revenue data for a multitude of products, in an effort to show the revenue impact of each product as it relates to the sum total of revenue. The data follows this format:
**Product** **Revenue** Gizmos 100000 Gadgets 200000 Whirligigs 125000
So the stacked bar chart should be a single bar showing the total revenue (425,000 for the example), comprised of three chunks stacked on one another (corresponding to Gizmos, Gadgets, and Whirligigs). Ideally, I’d like to add in a horizontal line representing this Quarter’s target revenue, as well - I know how to do that with standard bar charts, but I’m not 100% sure it’s supported with stacked bar charts.
The issue I’ve run into is that the standard implementation of stacked bar charts in Plotly seems to assume that each column is a new stack, when my data is arranged row-wise, and each new chunk of the stack is created using
go.Bar( x=df['x'], # assign x as the dataframe column 'x' y=df['y'] )
where y is the set of values for that chunk.
Is the answer here to transpose the data, such that it fits the following format:
**Quarter** **Gizmos** **Gadgets** **Whirligigs** Q1 100000 200000 125000 Q2 0 0 0 Q3 0 0 0
And then write a loop for the go.Bar() portion creating a trace for each product in sequence? I could theoretically do that, but it would be a bit annoying and potentially problematic since the number of products we have isn’t set in stone. Is there already a solution to creating row-wise stacked bar charts?