def rysuj_wykres(self, tablica_cash_flow, tablica_wolumenow, cf_laczone): try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: _fromUtf8 = lambda s: s self.qwtPlot.hide() self.qwtPlot.destroy() self.qwtPlot = Qwt.QwtPlot(self.tab_3) self.qwtPlot.setGeometry(QtCore.QRect(0, 0, 891, 256)) self.qwtPlot.setObjectName(_fromUtf8("qwtPlot")) self.qwtPlot.setAxisScale(Qwt.QwtPlot.xBottom, 0.0, len(tablica_cash_flow)) self.qwtPlot.setAxisScale( Qwt.QwtPlot.yLeft, min(cf_laczone), max(max(tablica_cash_flow), max(tablica_wolumenow))) grid = Qwt.QwtPlotGrid() grid.enableXMin(True) grid.enableYMin(True) grid.setMajPen(QtGui.QPen(QtGui.QColor(0, 0, 0), 1)) grid.setMinPen(QtGui.QPen(QtGui.QColor(100, 100, 100), 1)) grid.attach(self.qwtPlot) #histogram = HistogramItem() #histogram.setColor(QtGui.QColor(170,170,100)) numValues = len(tablica_cash_flow) intervals = [] values = Qwt.QwtArrayDouble(numValues) argumenty = range(len(values)) argumenty2 = [] for arg in argumenty: argumenty2.append(float(arg)) #argumenty2 = Qwt.QwtArrayDouble() i = 0 #for args in argumenty: curve = Qwt.QwtPlotCurve("Curve " + str(i)) curve.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 255, 0)), 2)) # cash flow zielone curve.setData(argumenty2, tablica_cash_flow) curve.attach(self.qwtPlot) i = 1 curve2 = Qwt.QwtPlotCurve("Curve " + str(i)) curve2.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor(255, 0, 0)), 2)) # wolumen czerwony curve2.setData(argumenty2, tablica_wolumenow) curve2.attach(self.qwtPlot) i = 3 curve3 = Qwt.QwtPlotCurve("Curve " + str(i)) curve3.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 255)), 2)) # suma niebieska curve3.setData(argumenty2, cf_laczone) curve3.attach(self.qwtPlot) self.qwtPlot.replot() self.qwtPlot.show()
def __init__(self, parent=None, name=''): Qwt.QwtPlot.__init__(self, parent) self._log = logging.getLogger(ConfigStatic.logger_name) self._log.info('passed') self.__name = name self._font_app = QtGui.QFont() dpi = 96 # TODO test physicalDpi (funguje v MainWindow.py) self._dpi2px = dpi*(1/2.54) self._plotSpeed = EnumPlotSpeed.oneCmMin self._plotBpm = EnumPlotBpm.twentyBpmCm self._plotBpmMajorTick = self._plotBpm #: Doc comment for instance attribute qux. self._minView = 0 self._maxView = 240 self._min_view_paper_lim = 0 self._max_view_paper_lim = 240 self._paper_format = EnumPaperFormat.EU self._minTime = 0 self._maxTime = 0 self._centerPoint = 0 self.__sampling_freq = 4 self._x = np.zeros(1) self._y = np.zeros(1) self._timeString = list() self._define_paper() # self.__canvasXMap = self.canvasMap(Qwt.QwtPlot.xBottom) # self.__canvasYMap = self.canvasMap(Qwt.QwtPlot.yLeft) self.setCanvasBackground(Qt.Qt.white) self.setAxisTitle(Qwt.QwtPlot.xBottom, "Time [min]") self.setAxisTitle(Qwt.QwtPlot.yLeft, "") # curves self.curve1 = Qwt.QwtPlotCurve('signal') # #self.curve1.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased) # self.curve1.setPen(QPen(Qt.Qt.black,0, Qt.Qt.SolidLine)) # self.curve1.setYAxis(Qwt.QwtPlot.yLeft) # self.curve1.attach(self) self._baseline = Qwt.QwtPlotMarker() ''' annotations ''' self.__d_ann_all_curves = dict() self.d_ann_all_curves_navplot = dict() self.__ann_action = 0 self.caliper = Caliper(self, EnumAnnType.plot_fhr, EnumAnnType.caliper) # self.caliper.plot() # time scale - for string time scale self.timeScale = TimeScaleDraw(self) self.setAxisScaleDraw(Qwt.QwtPlot.xBottom, self.timeScale) # time scale - for Y axis self.yAxisScale = AxisYScaleDraw(self) self.setAxisScaleDraw(Qwt.QwtPlot.yLeft, self.yAxisScale) self._bPlotDatesXAxis = False self._time_tics_located = list() self._locator_min = 5 self._locator_hour = 0 # grid self.grid = Qwt.QwtPlotGrid() self.grid.enableYMin(True) self.grid.enableXMin(True) self.grid.setMajPen(QtGui.QPen(Qt.Qt.lightGray, 0, Qt.Qt.SolidLine)) self.grid.setMinPen(QtGui.QPen(Qt.Qt.lightGray, 0, Qt.Qt.DotLine)) self.grid.attach(self) self.__set_axis_app_font()
def changePlotWidget(self, library, frame_for_plot): if library == "Qwt5" and has_qwt: plotWdg = QwtPlot(frame_for_plot) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( plotWdg.sizePolicy().hasHeightForWidth()) plotWdg.setSizePolicy(sizePolicy) plotWdg.setMinimumSize(QSize(0, 0)) plotWdg.setAutoFillBackground(False) #Decoration plotWdg.setCanvasBackground(Qt.white) plotWdg.plotLayout().setAlignCanvasToScales(True) zoomer = QwtPlotZoomer(QwtPlot.xBottom, QwtPlot.yLeft, QwtPicker.DragSelection, QwtPicker.AlwaysOff, plotWdg.canvas()) zoomer.setRubberBandPen(QPen(Qt.blue)) if platform.system() != "Windows": # disable picker in Windows due to crashes picker = QwtPlotPicker(QwtPlot.xBottom, QwtPlot.yLeft, QwtPicker.NoSelection, QwtPlotPicker.CrossRubberBand, QwtPicker.AlwaysOn, plotWdg.canvas()) picker.setTrackerPen(QPen(Qt.green)) #self.dockwidget.qwtPlot.insertLegend(QwtLegend(), QwtPlot.BottomLegend); grid = Qwt.QwtPlotGrid() grid.setPen(QPen(QColor('grey'), 0, Qt.DotLine)) grid.attach(plotWdg) return plotWdg elif library == "Matplotlib" and has_mpl: from matplotlib.figure import Figure from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg fig = Figure((1.0, 1.0), linewidth=0.0, subplotpars=matplotlib.figure.SubplotParams(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)) font = {'family': 'arial', 'weight': 'normal', 'size': 12} matplotlib.rc('font', **font) rect = fig.patch rect.set_facecolor((0.9, 0.9, 0.9)) self.subplot = fig.add_axes((0.07, 0.15, 0.92, 0.82)) self.subplot.set_xbound(0, 1000) self.subplot.set_ybound(0, 1000) self.manageMatplotlibAxe(self.subplot) canvas = FigureCanvasQTAgg(fig) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) canvas.setSizePolicy(sizePolicy) return canvas