plotting_test.py 3.15 KB
Newer Older
1
2
3
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
5
#   NScD Oak Ridge National Laboratory, European Spallation Source,
#   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
7
8
9
10
# SPDX - License - Identifier: GPL - 3.0 +
from PyQt4 import QtGui

import sys

Stephen Smith's avatar
Stephen Smith committed
11
from mantidqtinterfaces.Muon.GUI.Common import message_box
12

Stephen Smith's avatar
Stephen Smith committed
13
14
15
from mantidqtinterfaces.MultiPlotting.multi_plotting_widget import MultiPlotWidget
from mantidqtinterfaces.MultiPlotting.multi_plotting_context import *
from mantidqtinterfaces.MultiPlotting.label import Label
16
17
18
19
20
21
22
23
24
25

import mantid.simpleapi as mantid


class plotTestGui(QtGui.QMainWindow):

    def __init__(self, parent=None):
        super(plotTestGui, self).__init__(parent)
        self._context = PlottingContext()
        self.test = MultiPlotWidget(self._context, self)
26
        ws = setUpSubplot()
27
28
29
30
31
32
        self.test.add_subplot("test")
        self.test.add_subplot("bob")
        self.test.add_subplot("moo")
        self.test.add_subplot("baa")
        self.test.add_subplot("EXTRA")

Lorenzo Basso's avatar
Lorenzo Basso committed
33
34
35
        self.test.plot("test", ws, spec_num=26)
        self.test.plot("test", ws, spec_num=21)
        self.test.plot("test", ws, spec_num=22)
36
        # defines position of label
37
38
39
40
41
42
43
44
45
        dummy = Label("dummy", 10.1, False, 0.9, True, rotation=-90)
        dummy2 = Label(
            "protected",
            5.1,
            False,
            0.9,
            True,
            rotation=-90,
            protected=True)
46
47
48
49
        dummy3 = Label("just annotate", 14.1, False, 0.9, True)
        # defines position of line

        # need to add methods to add just a label
50
51
52
53
54
                # need to add_vline with a name and if protected but no
                # annotation

        self.test.add_vline_and_annotate("test", 10, dummy)
        self.test.add_vline_and_annotate("test", 5, dummy2)
55
56
        self.test.add_annotate("bob", dummy3)
        self.test.add_vline("bob", 1.2, "just a line")
57

Lorenzo Basso's avatar
Lorenzo Basso committed
58
59
60
61
        self.test.plot("bob", ws, spec_num=1)
        self.test.plot("EXTRA", ws, spec_num=42)
        self.test.plot("moo", ws, spec_num=42)
        self.test.plot("baa", ws, spec_num=2)
62
        self.test.set_all_values()
63

64
65
        self.test.connectCloseSignal(self.close)

66
67
68
        # add button for adding more plots
        self.n = 0
        self.ws = ws
69
        self.btn = QtGui.QPushButton("add plot")
70
71
72
73
74
75
76
        self.btn.clicked.connect(self.add)

        self.grid = QtGui.QSplitter(QtCore.Qt.Vertical)
        self.grid.addWidget(self.test)
        self.grid.addWidget(self.btn)

        self.setCentralWidget(self.grid)
77
78
79

        self.setWindowTitle("plot test")

80
    def add(self):
81
        self.n += 1
82
        self.test.add_subplot(str(self.n))
Lorenzo Basso's avatar
Lorenzo Basso committed
83
        self.test.plot(str(self.n), self.ws, spec_num=self.n)
84

85

86
def setUpSubplot():
87
    ws = mantid.LoadMuonNexus("MUSR00062260", OutputWorkspace="ws")
88
89
    return ws

90

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
def qapp():
    if QtGui.QApplication.instance():
        _app = QtGui.QApplication.instance()
    else:
        _app = QtGui.QApplication(sys.argv)
    return _app


app = qapp()
try:
    window = plotTestGui()
    window.show()
    app.exec_()
except RuntimeError as error:
    message_box.warning(str(error))