0

I am trying to create a stacked bar chart in Python to try and match the stacked bar chart produced by Excel but I can't seem to get it to match the output of Excel. The Python chart is not showing me values in the A array.excel chart python chart

import matplotlib.pyplot as plt

def graph2Peak(self):
    A = [-1478, -16411, 5986, 0]
    B = [14933, 29866, 7466, 14933]

    X = range(4)
    plt2 = plt

    plt.bar(X, A, color = 'b')
    plt.bar(X, B, color = 'r', bottom = A)

    plt.show()
craigcaulfield
  • 3,381
  • 10
  • 32
  • 40
DJS
  • 1
  • 1

1 Answers1

0

You need to ensure that the second bar is not starting from negative value.enter image description here

import matplotlib.pyplot as plt


def graph2Peak():
    A = [-1478, -16411, 5986, 0]
    B = [14933, 29866, 7466, 14933]

    X = range(4)
    plt2 = plt

    plt.bar(X, A, color = 'b')
    plt.bar(X, B, color = 'r', bottom = [0 if l<0 else l for l in A])

    plt.show()

graph2Peak()
Aritesh
  • 1,985
  • 1
  • 13
  • 17
  • Aritesh, Would you know how to be able to create multiple stacked bar charts into one Figure like the Excel sheet I attached? – DJS Mar 28 '18 at 00:44
  • Aritesh nevermind I was able to find some code to help me out. – DJS Mar 28 '18 at 03:45