Questions tagged [stacked-bar-chart]

A stacked bar chart is a graphical representation of data where, for each categorical group, there are two or more bars colored to represent a particular grouping. The value is represented by the length of the bar segment.

247 questions
147
votes
4 answers

Showing data values on stacked bar chart in ggplot2

I'd like to show data values on stacked bar chart in ggplot2. Here is my attempted code library(ggplot2) Data <- data.frame( Year = c(rep(c("2006-07", "2007-08", "2008-09", "2009-10"), each = 4)), Category = c(rep(c("A", "B", "C", "D"), times =…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
86
votes
10 answers

How to have clusters of stacked bars

So here is how my data set looks like : In [1]: df1=pd.DataFrame(np.random.rand(4,2),index=["A","B","C","D"],columns=["I","J"]) In [2]: df2=pd.DataFrame(np.random.rand(4,2),index=["A","B","C","D"],columns=["I","J"]) In [3]: df1 Out[3]: …
jrjc
  • 21,103
  • 9
  • 64
  • 78
81
votes
2 answers

Plot multiple columns of pandas DataFrame on the bar chart

I am using the following code to plot a bar-chart: import matplotlib.pyplot as pls my_df.plot(x='my_timestampe', y='col_A', kind='bar') plt.show() The plot works fine. However, I want to improve the graph by having 3 columns: 'col_A', 'col_B',…
Edamame
  • 23,718
  • 73
  • 186
  • 320
81
votes
5 answers

Plotting a stacked Bar Chart

I am trying to create a stacked bar graph with pandas that replicates the picture, all my data is separate from that excel spreadsheet. I can't figure out how to make a dataframe for it like pictured, nor can I figure out how to make the stacked…
Kuzen
  • 950
  • 3
  • 10
  • 15
59
votes
6 answers

stacked bar plot using matplotlib

I am generating bar plots using matplotlib and it looks like there is a bug with the stacked bar plot. The sum for each vertical stack should be 100. However, for X-AXIS ticks 65, 70, 75 and 80 we get completely arbitrary results which do not make…
tandem
  • 2,040
  • 4
  • 25
  • 52
31
votes
2 answers

Stacked Bar Chart with Centered Labels

I'm trying to "robustly" center the data labels in a stacked bar chart. A simple code example and the result are given below. As you can see, the data labels aren't really centered in all rectangles. What am I missing? import numpy as np import…
Bruno
  • 1,329
  • 2
  • 15
  • 35
13
votes
2 answers

Stacked bar chart in Seaborn

I have the following data: countries2012 = [ 'Bolivia', 'Brazil', 'Sri Lanka', 'Dominican Republic', 'Indonesia', 'Kenya', 'Honduras', 'Mozambique', 'Peru', 'Philipines', 'India', 'Vietnam', …
Corp. and Ltd.
  • 401
  • 2
  • 5
  • 17
8
votes
2 answers

Display totals and percentage in stacked bar chart using DataFrame.plot

My data frame looks like below: Airport ATA Cost Destination Handling Custom Total Cost PRG 599222 11095 20174 630491 LXU 364715 11598 11595 387908 AMS 401382 23562 16680 441623 PRG 599222 11095 20174 630491 Using below codes it…
Jack
  • 1,339
  • 1
  • 12
  • 31
6
votes
1 answer

How to stack 3d bar charts

Essentially a 3d version of this: Plot two histograms at the same time with matplotlib Though I don't know how to do it since I am using Axes 3d. from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np kets =…
M.V.
  • 121
  • 2
  • 9
4
votes
1 answer

stacked and grouped barchart

I have this data set import pandas as pd import plotly.express as px elements = pd.DataFrame(data={"Area": ["A", "A", "A", "B", "B", "C", "C", "C"], "Branch": ["a1", "f55", "j23", "j99", "ci2", "p21", "o2", "q35"], "Good": [68, 3, 31, 59, 99, 86,…
4
votes
1 answer

Stacked chart with multiple categories stored in a SINGLE column – Google Sheets

I need to create a stacked column chart with Date aggregated on X-axis, and the bars with multiple (dynamically formed?) Category series. All of the examples out there demonstrate how to create the stacked graphs with the separate columns for each…
4
votes
1 answer

How to annotate each segment of a stacked bar chart

I've been trying to annotate each sub-amount of a stacked bar chart with its values like the picture shown above (values not accurate, just an example). df.iloc[1:].T.plot(kind='bar', stacked=True) plt.show() Data frame that I used: The linked…
abc
  • 399
  • 4
  • 18
4
votes
1 answer

Combining two stacked bar plots for a grouped stacked bar plot

So I found the following code online: import matplotlib.pyplot as plt import matplotlib matplotlib.style.use('ggplot') plotdata = pd.DataFrame({ "2018_m":[40, 12, 10, 26, 36], "2019_m":[19, 8, 30, 21, 38], "2020_m":[10, 10, 42, 17,…
3
votes
1 answer

Stacked butterfly/tornado graph with ggplot2, centered on zero, for visualising before-and-after likert questionnaires

I have data from a questionnaire given before and after an educational module. I am trying to visualise the data with ggplot in a stacked bar chart, more specifically stacked butterfly/tornado graph, where I want to make the two different occasions…
3
votes
1 answer

Add different labels to show totals in stacked bar plot in ggplot R?

My question is somewhat similar to this: How to add text label to show total n in each bar of stacked proportion bars in ggplot? However, the solutions offered there don't work in my case because the stacked bars are not always the same height and…
lu-202
  • 121
  • 7
1
2 3
16 17