👀
Crash Visualization
  • Welcome
  • Preface
    • Who the book is written for
    • How the book is organized
  • 1. Introduction of Data Visualization
    • 1.1 What is data visualization?
    • 1.2 Why does visualization matter?
  • 2. Tricks in Visualization
    • 2.1 Choose Appropriate Chart
    • 2.2 Features of Charts
      • 2.2.1 Table
      • 2.2.2 Column Chart
      • 2.2.3 Line Chart
      • 2.2.4 Pie Chart
      • 2.2.5 Scatter Chart
      • 2.2.6 Map Chart
    • 2.3 Misused Graph
    • 2.4 Tips in Visualization
  • 3. Matplotlib
    • 3.1 Basic Concepts
    • 3.2 Line Chart
    • 3.3 Area Chart
    • 3.4 Column Chart
    • 3.5 Histogram Chart
    • 3.6 Scatter Chart
    • 3.7 Lollipop Chart
    • 3.8 Pie Chart
    • 3.9 Venn Chart
    • 3.10 Waffle Chart
    • 3.11 Animation
  • 4. Seaborn
    • 4.1 Trends
    • 4.2 Ranking
      • 4.2.1 Barplot
      • 4.2.2 Boxplot
    • 4.3 Composition
      • 4.3.1 Stacked Chart
    • 4.4 Correlation
      • 4.4.1 Scatter Plot
      • 4.4.2 Linear Relationship
      • 4.4.3 Heatmap
      • 4.4.4 Pairplot
    • 4.5 Distribution
      • 4.5.1 Boxplot
      • 4.5.2 Violin plot
      • 4.5.3 Histogram plot
      • 4.5.4 Density plot
      • 4.5.5 Joint plot
  • 5. Bokeh
    • 5.1 Basic Plotting
    • 5.2 Data Sources
    • 5.3 Annotations
    • 5.4 Categorical Data
    • 5.5 Presentation and Layouts
    • 5.6 Linking and Interactions
    • 5.7 Network Graph
    • 5.8 Widgets
  • 6. Plotly
    • 6.1 Fundamental Concepts
      • 6.1.1 Plotly Express
      • 6.1.2 Plotly Graph Objects
    • 6.2 Advanced Charts
      • 6.2.1 Advanced Scatter Chart
      • 6.2.2 Advanced Bar Chart
      • 6.2.3 Advanced Pie Chart
      • 6.2.4 Advanced Heatmap
      • 6.2.5 Sankey Chart
      • 6.2.6 Tables
    • 6.3 Statistical Charts
      • 6.3.1 Common Statistical Charts
      • 6.3.2 Dendrograms
      • 6.3.3 Radar Chart
      • 6.3.4 Polar Chart
      • 6.3.5 Streamline Chart
    • 6.4 Financial Charts
      • 6.4.1 Funnel Chart
      • 6.4.2 Candlestick Chart
      • 6.4.3 Waterfall Chart
  • Support
    • Donation
Powered by GitBook
On this page
  • 1. Stacked 100% Column Chart
  • 2. Stacked Column Chart
  • 3. Stacked 100% Area Chart
  • 4. Stacked Area Chart

Was this helpful?

  1. 4. Seaborn
  2. 4.3 Composition

4.3.1 Stacked Chart

Previous4.3 CompositionNext4.4 Correlation

Last updated 4 years ago

Was this helpful?

It's very important to choose the proper chart to illustrate the composition. There are some tips:

  • If the change is static, consider a or .

  • If the change is over time, consider a stacked chart.

    • If only a few periods and only presents relative differences, use a stacked 100% column chart.

    • If only a few periods and presents relative and absolute differences, use a stacked column chart.

    • If it has many periods and presents relative differences, use a stacked 100% area chart.

    • if it has many periods and presents relative and absolute differences, use a stacked area chart.

1. Stacked 100% Column Chart

Let's create a fruit sales dataset and calculate each items' percentage.

raw = {'time':['Q1','Q2','Q3','Q4'], 
        'apple':[1000,2000, 1550, 1800],
        'banana':[3000,4000, 3300, 2000],
        'kiwi':[500, 1200, 2800, 1500]}
df = pd.DataFrame(raw)

# From value to percentage
total = [i+j+k for i,j,k in zip(df['apple'], df['banana'], df['kiwi'])]
apple = [i / j * 100 for i,j in zip(df['apple'], total)]
banana = [i / j * 100 for i,j in zip(df['banana'], total)]
kiwi = [i / j * 100 for i,j in zip(df['kiwi'], total)]
plt.figure(figsize = (12,8))

sns.barplot(time, apple, color='salmon',label = 'Apple')
sns.barplot(time, banana, color='gold',bottom = apple,  label = 'Banana')
sns.barplot(time, kiwi, color='lightgreen', bottom=[i+j for i,j in zip(apple, banana)],label = 'Kiwi')

plt.legend(ncol=3, loc="best", frameon=True)

2. Stacked Column Chart

plt.figure(figsize = (12,8))
sns.barplot(x="time", y="apple",data = fruit, label="Apple", 
                color="salmon")
sns.barplot(x="time", y="banana",data = fruit, label="Banana", 
                color="gold",alpha = 0.5)
sns.barplot(x="time", y="kiwi", data = fruit,label="Kiwi", 
                color="lightgreen",alpha = 0.5)

plt.legend(ncol=1, loc="best", frameon=True)

3. Stacked 100% Area Chart

plt.figure(figsize = (12,8))
plt.stackplot(time, apple, banana,kiwi , labels=['Apple','Banana','Kiwi'])
plt.legend(loc='best')
plt.margins(0,0)
plt.title('100 % stacked area chart')
plt.show()

4. Stacked Area Chart

plt.figure(figsize = (12,8))
plt.stackplot(time,[fruit['apple'],fruit['banana'],fruit['kiwi']], labels=['Apple','Banana','Kiwi'] )
plt.legend(loc='upper right')
plt.title('Stacked area chart')
plt.show()
pie chart
waterfall
Stacked 100% Column Chart
Stacked Area Chart