<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<DIV>Hi everyone,</DIV>
<DIV> </DIV>
<DIV>in my script I’m trying to display a stacked bar graph using matplotlib
(0.99.1). Here is a piece of runnable code showing what I’m aiming to do:</DIV>
<DIV> </DIV>
<DIV>import sys, os, random</DIV>
<DIV>from PyQt4 import QtGui, QtCore</DIV>
<DIV> </DIV>
<DIV>import numpy</DIV>
<DIV>from numpy import arange, sin, pi</DIV>
<DIV>from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as
FigureCanvas</DIV>
<DIV>from matplotlib.figure import Figure</DIV>
<DIV> </DIV>
<DIV>progname = os.path.basename(sys.argv[0])</DIV>
<DIV> </DIV>
<DIV>class MyMplCanvas(FigureCanvas):</DIV>
<DIV> """Ultimately, this is a QWidget (as well as a
FigureCanvasAgg, etc.)."""</DIV>
<DIV> def __init__(self, parent=None, width=5, height=4,
dpi=100):</DIV>
<DIV> fig = Figure(figsize=(width,
height), dpi=dpi)</DIV>
<DIV> self.axes =
fig.add_subplot(111)</DIV>
<DIV> # We want the axes cleared every
time plot() is called</DIV>
<DIV> self.axes.hold(False)</DIV>
<DIV> </DIV>
<DIV> self.figure = fig</DIV>
<DIV> FigureCanvas.__init__(self,
fig)</DIV>
<DIV> self.setParent(parent)</DIV>
<DIV> </DIV>
<DIV>
FigureCanvas.setSizePolicy(self,</DIV>
<DIV>
QtGui.QSizePolicy.Expanding,</DIV>
<DIV>
QtGui.QSizePolicy.Expanding)</DIV>
<DIV>
FigureCanvas.updateGeometry(self)</DIV>
<DIV>
self.compute_initial_figure()</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>class MyStaticMplCanvas(MyMplCanvas):</DIV>
<DIV> """Simple canvas with a sine plot."""</DIV>
<DIV> def compute_initial_figure(self):</DIV>
<DIV> N = 10</DIV>
<DIV> A = numpy.array([70, 88, 78, 93,
99, 58, 89, 66, 77, 78])</DIV>
<DIV> B = numpy.array([73, 65, 78, 87,
97, 57, 77, 88, 69, 78])</DIV>
<DIV> C = numpy.array([66, 98, 88, 67,
99, 88, 62, 70, 90, 73])</DIV>
<DIV> </DIV>
<DIV> ind = numpy.arange(N)</DIV>
<DIV> width = 0.35</DIV>
<DIV> </DIV>
<DIV> p1 = self.axes.bar(ind, A,width,
color='r')</DIV>
<DIV> p2 = self.axes.bar(ind, B,
width, color='y', bottom=A)</DIV>
<DIV> p3 = self.axes.bar(ind, C,
width, color='b', bottom=A+B)</DIV>
<DIV> </DIV>
<DIV>class ApplicationWindow(QtGui.QMainWindow):</DIV>
<DIV> def __init__(self):</DIV>
<DIV>
QtGui.QMainWindow.__init__(self)</DIV>
<DIV>
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)</DIV>
<DIV> self.setWindowTitle("application
main window")</DIV>
<DIV> </DIV>
<DIV> self.main_widget =
QtGui.QWidget(self)</DIV>
<DIV> </DIV>
<DIV> l =
QtGui.QVBoxLayout(self.main_widget)</DIV>
<DIV> sc =
MyStaticMplCanvas(self.main_widget, width=5, height=4, dpi=100)</DIV>
<DIV> l.addWidget(sc)</DIV>
<DIV> </DIV>
<DIV>
self.setCentralWidget(self.main_widget)</DIV>
<DIV> </DIV>
<DIV>qApp = QtGui.QApplication(sys.argv)</DIV>
<DIV> </DIV>
<DIV>aw = ApplicationWindow()</DIV>
<DIV>aw.show()</DIV>
<DIV>sys.exit(qApp.exec_())</DIV>
<DIV> </DIV>
<DIV>if you run the code you will see that the bars are not stacked, since only
the last graph is shown. Is it a bug or am I missing something? if so can anyone
point me out what I am doing wrong? Thanks in
advance.</DIV></DIV></DIV></BODY></HTML>