From cf8edd5bd1d5fd8c7e64f6df726d3f8272432e9d Mon Sep 17 00:00:00 2001 From: 45coll <674148718@qq.com> Date: Fri, 17 Sep 2021 16:15:51 +0800 Subject: [PATCH] 9.17.2 --- python_gui/gui/main.py | 2 ++ python_gui/gui/sharedcomponets.py | 1 - python_gui/gui/test1.py | 47 +++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/python_gui/gui/main.py b/python_gui/gui/main.py index f41e04b..78e77b6 100644 --- a/python_gui/gui/main.py +++ b/python_gui/gui/main.py @@ -48,8 +48,10 @@ class MyWindow(QMainWindow, Ui_MainWindow): self.re_item = [] def plot_init(self): # 绘图对象 + pg.setConfigOptions(antialias=True) self.plotWidget = pg.PlotWidget() self.plotWidget.showGrid(x=True, y=True, alpha=0.5) + self.plotWidget.addLegend() self.controlPlotWidget = ControlPlotPanel(controllerPlotWidget=self) # 图表可视化数组 self.numberOfSamples = 300 diff --git a/python_gui/gui/sharedcomponets.py b/python_gui/gui/sharedcomponets.py index 76b52f2..60a49e4 100644 --- a/python_gui/gui/sharedcomponets.py +++ b/python_gui/gui/sharedcomponets.py @@ -67,7 +67,6 @@ class GUIToolKit(object): } currentDir = os.path.dirname(__file__) icon_path = os.path.join(currentDir, './resources', file_index[icoName]) - print(icon_path) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(icon_path), QtGui.QIcon.Normal, QtGui.QIcon.Off) diff --git a/python_gui/gui/test1.py b/python_gui/gui/test1.py index e69de29..0e68103 100644 --- a/python_gui/gui/test1.py +++ b/python_gui/gui/test1.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +""" +Demonstrates basic use of LegendItem + +""" +# import initExample ## Add path to library (just for examples; you do not need this) + +import pyqtgraph as pg +from pyqtgraph.Qt import QtCore, QtGui +import numpy as np + +win = pg.plot() +win.setWindowTitle('pyqtgraph example: BarGraphItem') + +# # option1: only for .plot(), following c1,c2 for example----------------------- +# win.addLegend(frame=False, rowCount=1, colCount=2) + +# bar graph +x = np.arange(10) +y = np.sin(x+2) * 3 +bg1 = pg.BarGraphItem(x=x, height=y, width=0.3, brush='b', pen='w', name='bar') +win.addItem(bg1) + +# curve +c1 = win.plot([np.random.randint(0,8) for i in range(10)], pen='r', symbol='t', symbolPen='r', symbolBrush='g', name='curve1') +c2 = win.plot([2,1,4,3,1,3,2,4,3,2], pen='g', fillLevel=0, fillBrush=(255,255,255,30), name='curve2') + +# scatter plot +s1 = pg.ScatterPlotItem(size=10, pen=pg.mkPen(None), brush=pg.mkBrush(255, 255, 255, 120), name='scatter') +spots = [{'pos': [i, np.random.randint(-3, 3)], 'data': 1} for i in range(10)] +s1.addPoints(spots) +win.addItem(s1) + +# # option2: generic method------------------------------------------------ +legend = pg.LegendItem((80,60), offset=(70,20)) +legend.setParentItem(win.graphicsItem()) +legend.addItem(bg1, 'bar') +legend.addItem(c1, 'curve1') +legend.addItem(c2, 'curve2') +legend.addItem(s1, 'scatter') + + +## Start Qt event loop unless running in interactive mode or using pyside. +if __name__ == '__main__': + import sys + if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): + QtGui.QApplication.instance().exec_()