diff --git a/Framework/PythonInterface/mantid/plots/utility.py b/Framework/PythonInterface/mantid/plots/utility.py index 2e69e98908026787bb9fc91965b4fe7410910aed..4daa1a6d3a8fb78b0dc3a1707645de8762fa6452 100644 --- a/Framework/PythonInterface/mantid/plots/utility.py +++ b/Framework/PythonInterface/mantid/plots/utility.py @@ -7,15 +7,22 @@ # This file is part of the mantid package from __future__ import absolute_import +from collections import namedtuple from contextlib import contextmanager -from matplotlib import cm +from matplotlib import cm, __version__ as mpl_version_str from matplotlib.container import ErrorbarContainer from matplotlib.legend import Legend from enum import Enum +# matplotlib version information +MPLVersionInfo = namedtuple("MPLVersionInfo", ("major", "minor", "patch")) +MATPLOTLIB_VERSION_INFO = MPLVersionInfo._make(map(int, mpl_version_str.split("."))) + + +# Use the correct draggable method based on the matplotlib version if hasattr(Legend, "set_draggable"): SET_DRAGGABLE_METHOD = "set_draggable" else: @@ -132,6 +139,11 @@ def legend_set_draggable(legend, state, use_blit=False, update='loc'): getattr(legend, SET_DRAGGABLE_METHOD)(state, use_blit, update) +def mpl_version_info(): + """Returns a namedtuple of (major,minor,patch)""" + return MATPLOTLIB_VERSION_INFO + + def zoom_axis(ax, coord, x_or_y, factor): """ Zoom in around the value 'coord' along the given axis. diff --git a/qt/python/mantidqt/widgets/colorbar/colorbar.py b/qt/python/mantidqt/widgets/colorbar/colorbar.py index 56b55d6d2a8c1d2f00e07aff6e62755c10dc3ac5..41eea96614c968d8f2c936ab0cfbd3feeaab84bb 100644 --- a/qt/python/mantidqt/widgets/colorbar/colorbar.py +++ b/qt/python/mantidqt/widgets/colorbar/colorbar.py @@ -8,22 +8,24 @@ # # from __future__ import (absolute_import, division, print_function) -from qtpy.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLineEdit, QComboBox, QCheckBox, QLabel -from qtpy.QtCore import Signal -from qtpy.QtGui import QDoubleValidator + +from mantid.plots.utility import mpl_version_info +from mantidqt.MPLwidgets import FigureCanvas from matplotlib.colorbar import Colorbar from matplotlib.figure import Figure -from mantidqt.MPLwidgets import FigureCanvas from matplotlib.colors import Normalize, SymLogNorm, PowerNorm from matplotlib import cm import numpy as np +from qtpy.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLineEdit, QComboBox, QCheckBox, QLabel +from qtpy.QtCore import Signal +from qtpy.QtGui import QDoubleValidator NORM_OPTS = ["Linear", "SymmetricLog10", "Power"] class ColorbarWidget(QWidget): - colorbarChanged = Signal() # The parent should simply redraw their canvas + colorbarChanged = Signal() # The parent should simply redraw their canvas def __init__(self, parent=None): super(ColorbarWidget, self).__init__(parent) @@ -108,18 +110,21 @@ class ColorbarWidget(QWidget): except AttributeError: # else default cmap = None self.colorbar = Colorbar(ax=self.ax, mappable=mappable) - self.cmin_value, self.cmax_value = self.colorbar.get_clim() + self.cmin_value, self.cmax_value = mappable.get_clim() self.update_clim_text() self.cmap_changed(cmap) - self.cmap.setCurrentIndex(sorted(cm.cmap_d.keys()).index(self.colorbar.get_cmap().name)) + self.cmap.setCurrentIndex(sorted(cm.cmap_d.keys()).index(mappable.get_cmap().name)) self.redraw() def cmap_index_changed(self): self.cmap_changed(self.cmap.currentText()) def cmap_changed(self, name): - self.colorbar.set_cmap(name) self.colorbar.mappable.set_cmap(name) + if mpl_version_info() >= (3, 1): + self.colorbar.update_normal(self.colorbar.mappable) + else: + self.colorbar.set_cmap(name) self.redraw() def mappable_changed(self): @@ -128,13 +133,11 @@ class ColorbarWidget(QWidget): when the plot changes via settings. """ mappable_cmap = self.colorbar.mappable.get_cmap() - low,high = self.colorbar.mappable.get_clim() - self.colorbar.set_cmap(mappable_cmap) - self.colorbar.set_clim(low,high) + low, high = self.colorbar.mappable.get_clim() self.cmin_value = low self.cmax_value = high self.update_clim_text() - self.cmap.setCurrentIndex(sorted(cm.cmap_d.keys()).index(self.colorbar.get_cmap().name)) + self.cmap.setCurrentIndex(sorted(cm.cmap_d.keys()).index(mappable_cmap.name)) self.redraw() def norm_changed(self): @@ -208,9 +211,9 @@ class ColorbarWidget(QWidget): cmax = float(self.cmax.text()) if cmax > self.cmin_value: self.cmax_value = cmax - else: #reset values back + else: # reset values back self.update_clim_text() - self.colorbar.set_clim(self.cmin_value, self.cmax_value) + self.colorbar.mappable.set_clim(self.cmin_value, self.cmax_value) self.redraw() def update_clim_text(self): diff --git a/qt/python/mantidqt/widgets/sliceviewer/toolbar.py b/qt/python/mantidqt/widgets/sliceviewer/toolbar.py index 5d00364c4d47ae633f71d0b1acdff87e81c44075..f3e3c39a0de5eb4d01ab3d68aaea0db54422afd1 100644 --- a/qt/python/mantidqt/widgets/sliceviewer/toolbar.py +++ b/qt/python/mantidqt/widgets/sliceviewer/toolbar.py @@ -51,8 +51,6 @@ class SliceViewerNavigationToolbar(NavigationToolbar2QT): if tooltip_text is not None: a.setToolTip(tooltip_text) - self.buttons = {} - # Add the x,y location widget at the right side of the toolbar # The stretch factor is 1 which means any resizing of the toolbar # will resize this label instead of the buttons. diff --git a/qt/python/mantidqt/widgets/sliceviewer/view.py b/qt/python/mantidqt/widgets/sliceviewer/view.py index 384b790f6c7c9b40d2c395a332d2d177c81083ed..c1f4865daca0dfed58a40e003213c72cdc91a87e 100644 --- a/qt/python/mantidqt/widgets/sliceviewer/view.py +++ b/qt/python/mantidqt/widgets/sliceviewer/view.py @@ -8,6 +8,7 @@ # # from __future__ import (absolute_import, division, print_function) + from matplotlib import gridspec from matplotlib.figure import Figure from matplotlib.transforms import Bbox, BboxTransform @@ -149,14 +150,14 @@ class SliceViewerView(QWidget): self.presenter.line_plots() def clear_line_plots(self): - try: # clear old plots + try: # clear old plots del self.xfig del self.yfig except AttributeError: pass def update_data_clim(self): - self.im.set_clim(self.colorbar.colorbar.get_clim()) # force clim update, needed for RHEL7 + self.im.set_clim(self.colorbar.colorbar.mappable.get_clim()) self.canvas.draw_idle() def update_line_plot_limits(self):