Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source
# & Institut Laue - Langevin
# SPDX - License - Identifier: GPL - 3.0 +
# This file is part of the mantid workbench.
#
#
from __future__ import (absolute_import, division, print_function)
from qtpy.QtWidgets import QWidget, QVBoxLayout
from qtpy.QtCore import Signal, Qt
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvas, NavigationToolbar2QT as NavigationToolbar
from .dimensionwidget import DimensionWidget
class SliceViewerView(QWidget):
dimensionsChanged = Signal()
valueChanged = Signal()
def __init__(self, dims_info, parent=None):
super(SliceViewerView, self).__init__(parent)
self.setWindowTitle("SliceViewer")
self.setWindowFlags(Qt.Window)
self.setAttribute(Qt.WA_DeleteOnClose, True)
# Dimension widget
self.dimensions = DimensionWidget(dims_info, parent=self)
self.dimensions.dimensionsChanged.connect(self.dimensionsChanged)
self.dimensions.valueChanged.connect(self.valueChanged)
# MPL figure
self.fig = Figure()
self.fig.set_tight_layout(True)
self.canvas = FigureCanvas(self.fig)
self.ax = self.fig.add_subplot(111, projection='mantid')
# MPL toolbar
self.mpl_toolbar = NavigationToolbar(self.canvas, self)
# layout
self.layout = QVBoxLayout(self)
self.layout.addWidget(self.dimensions)
self.layout.addWidget(self.mpl_toolbar)
self.layout.addWidget(self.canvas, stretch=1)
self.show()
def plot(self, ws, **kwargs):
"""
clears the plot and creates a new one using the workspace
"""
self.ax.clear()
try:
self.colorbar.remove()
except AttributeError:
pass
self.im = self.ax.imshow(ws, origin='lower', **kwargs)
self.ax.set_title('')
self.colorbar = self.fig.colorbar(self.im)
self.mpl_toolbar.update() # clear nav stack
self.fig.canvas.draw_idle()
def update_plot_data(self, data):
"""
This just updates the plot data without creating a new plot
"""
self.im.set_data(data.T)
self.im.set_clim(data.min(), data.max())
self.fig.canvas.draw_idle()
def closeEvent(self, event):
self.deleteLater()
super(SliceViewerView, self).closeEvent(event)