def make(): demo = QwtPlot() demo.setCanvasBackground(Qt.white) demo.setTitle("Histogram") grid = QwtPlotGrid() grid.enableXMin(True) grid.enableYMin(True) grid.setMajorPen(QPen(Qt.black, 0, Qt.DotLine)) grid.setMinorPen(QPen(Qt.gray, 0, Qt.DotLine)) grid.attach(demo) histogram = HistogramItem() histogram.setColor(Qt.darkCyan) numValues = 20 samples = [] pos = 0.0 for i in range(numValues): width = 5 + random.randint(0, 4) value = random.randint(0, 99) samples.append(QwtIntervalSample(value, QwtInterval(pos, pos + width))) pos += width histogram.setData(QwtIntervalSeriesData(samples)) histogram.attach(demo) demo.setAxisScale(QwtPlot.yLeft, 0.0, 100.0) demo.setAxisScale(QwtPlot.xBottom, 0.0, pos) demo.replot() demo.resize(600, 400) demo.show() return demo
def __init__(self, *args): QwtPlot.__init__(self, *args) self.curves = {} self.data = {} self.timeData = 1.0 * np.arange(0, HISTORY, 1) self.MemStat = MemStat() self.setAutoReplot(False) self.plotLayout().setAlignCanvasToScales(True) self.setAxisScale(QwtPlot.xBottom, HISTORY, 0) self.setAxisScale(QwtPlot.yLeft, 0, 100) self.setAxisLabelAlignment(QwtPlot.xBottom, Qt.AlignLeft | Qt.AlignBottom) grid = QwtPlotGrid() grid.enableXMin(True) grid.enableYMin(True) grid.setMajPen(QPen(Qt.black, 0, Qt.DotLine)) grid.setMinPen(QPen(Qt.gray, 0, Qt.DotLine)) grid.attach(self) stat = MemStat.statistic() self.data["MemTotal"] = np.zeros(HISTORY, float) self.data["MemFree"] = np.zeros(HISTORY, float) self.data["SwapTotal"] = np.zeros(HISTORY, float) self.data["SwapFree"] = np.zeros(HISTORY, float) curve = MemoryCurve("Memory") curve.setColor(self.colors[0]) curve.attach(self) self.curves["Memory"] = curve self.data["Memory"] = np.zeros(HISTORY, float) curve = MemoryCurve("Swap") curve.setColor(self.colors[1]) curve.attach(self) self.curves["Swap"] = curve self.data["Swap"] = np.zeros(HISTORY, float) self.startTimer(1000) self.replot()