Skip to content
Snippets Groups Projects
Commit e34ea8a0 authored by Stephen's avatar Stephen
Browse files

Re-structuring and renaming files in Muon script directory

parent 171d4171
No related branches found
No related tags found
No related merge requests found
Showing
with 99 additions and 310 deletions
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
# Copyright © 2020 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2020 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
......@@ -10,8 +10,7 @@ from math import sqrt, ceil, floor
from distutils.version import LooseVersion
from qtpy import QT_VERSION, QtGui
from Muon.GUI.Common.plotting_widget.external_plotting_model import PlotInformation
from Muon.GUI.Common.plot_widget.external_plotting.external_plotting_model import PlotInformation
from mantid.plots.utility import legend_set_draggable
......
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# Copyright © 2020 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from Muon.GUI.Common.plotting_widget.plotting_canvas_widget import PlottingCanvasWidget
from Muon.GUI.Common.plotting_widget.plotting_widget_presenter1 import PlotWidgetPresenterCommon
from Muon.GUI.Common.plotting_widget.plotting_widget_view import PlotWidgetView
from Muon.GUI.Common.plotting_widget.plotting_widget_presenter import PlotWidgetPresenter
from Muon.GUI.Common.plotting_widget.plotting_widget_model1 import PlotWidgetModel as PlotWidgetModel
from Muon.GUI.Common.plotting_widget.plotting_widget_model import PlotWidgetModel as PlotWidgetModel2
from Muon.GUI.Common.plotting_widget.plotting_widget_view1 import PlotWidgetView1
from Muon.GUI.Common.plot_widget.plotting_canvas.plotting_canvas_widget import PlottingCanvasWidget
from Muon.GUI.Common.plot_widget.plot_widget_presenter import PlotWidgetPresenterCommon
from Muon.GUI.Common.plot_widget.plot_widget_view import PlotWidgetView
from Muon.GUI.Common.plot_widget.plot_widget_model import PlotWidgetModel as PlotWidgetModel
class PlottingWidget(object):
class PlotWidget(object):
def __init__(self, context=None, parent=None):
self.view = PlotWidgetView(parent=parent)
self.model = PlotWidgetModel2()
self.presenter = PlotWidgetPresenter(self.view,
self.model,
context)
context.update_plots_notifier.add_subscriber(self.presenter.workspace_replaced_in_ads_observer)
context.deleted_plots_notifier.add_subscriber(self.presenter.workspace_deleted_from_ads_observer)
def close(self):
self.view.close()
class PlottingWidget1(object):
def __init__(self, context=None, parent=None):
# The plotting canvas widiget
# The plotting canvas widget
self.plotting_canvas_widget = PlottingCanvasWidget(parent, context=context)
# The UI view
self.view = PlotWidgetView1(parent)
self.view = PlotWidgetView(parent)
self.view.add_canvas_widget(self.plotting_canvas_widget.widget)
self.model = PlotWidgetModel(context)
# generate the presenter
self.presenter = PlotWidgetPresenterCommon(self.view,
self.model,
context,
self.plotting_canvas_widget.presenter)
self.model,
context,
self.plotting_canvas_widget.presenter)
context.update_plots_notifier.add_subscriber(self.presenter.workspace_replaced_in_ads_observer)
context.deleted_plots_notifier.add_subscriber(self.presenter.workspace_deleted_from_ads_observer)
@property
def plot_canvas_widget(self):
return self.plotting_canvas_widget
def close(self):
self.view.close()
......@@ -156,8 +156,8 @@ class PlotWidgetModel(object):
plot_types = [ASYMMETRY_PLOT_TYPE, COUNTS_PLOT_TYPE]
if self.context._frequency_context:
for ext in FREQUENCY_EXTENSIONS.keys():
plot_types.insert(FREQ_PLOT_TYPE + FREQUENCY_EXTENSIONS[ext])
plot_types.insert(FREQ_PLOT_TYPE + "All")
plot_types.append(FREQ_PLOT_TYPE + FREQUENCY_EXTENSIONS[ext])
plot_types.append(FREQ_PLOT_TYPE + "All")
return plot_types
def _generate_run_indicies(self, workspace_list):
......
......@@ -4,27 +4,29 @@
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from typing import Dict
from typing import Dict, List
from Muon.GUI.Common.contexts.fitting_context import FitInformation
from Muon.GUI.Common.home_tab.home_tab_presenter import HomeTabSubWidget
from Muon.GUI.Common.plotting_widget.external_plotting_model import ExternalPlottingModel
from Muon.GUI.Common.plotting_widget.external_plotting_view import ExternalPlottingView
from Muon.GUI.Common.plotting_widget.plotting_canvas_presenter_interface import PlottingCanvasPresenterInterface
from Muon.GUI.Common.plotting_widget.plotting_widget_model1 import PlotWidgetModel
from Muon.GUI.Common.plotting_widget.plotting_widget_view_interface import PlottingWidgetViewInterface
from mantidqt.utils.observer_pattern import GenericObserver, GenericObserverWithArgPassing
from Muon.GUI.Common.plot_widget.external_plotting.external_plotting_model import ExternalPlottingModel
from Muon.GUI.Common.plot_widget.external_plotting.external_plotting_view import ExternalPlottingView
from Muon.GUI.Common.plot_widget.plotting_canvas.plotting_canvas_presenter_interface import \
PlottingCanvasPresenterInterface
from Muon.GUI.Common.plot_widget.plot_widget_model import PlotWidgetModel
from Muon.GUI.Common.plot_widget.plot_widget_view_interface import PlotWidgetViewInterface
from mantidqt.utils.observer_pattern import GenericObserver, GenericObserverWithArgPassing, GenericObservable
from mantid.dataobjects import Workspace2D
class PlotWidgetPresenterCommon(HomeTabSubWidget):
def __init__(self, view: PlottingWidgetViewInterface, model: PlotWidgetModel, context,
def __init__(self, view: PlotWidgetViewInterface, model: PlotWidgetModel, context,
figure_presenter: PlottingCanvasPresenterInterface):
"""
:param view: A reference to the QWidget object for plotting
:param model: A reference to a model which contains the plotting logic
:param context: A reference to the Muon context object
:param figure_presenter: A reference to a figure presenter, which is used as an interface to plotting
"""
if not isinstance(figure_presenter, PlottingCanvasPresenterInterface):
raise TypeError("Parameter figure_presenter must be of type PlottingCanvasPresenterInterface")
......@@ -39,9 +41,8 @@ class PlotWidgetPresenterCommon(HomeTabSubWidget):
# gui observers
self._setup_gui_observers()
# Connect to the view
self._setup_view_connections()
# setup view options
self.update_view_from_model()
def update_view_from_model(self):
......@@ -61,6 +62,9 @@ class PlotWidgetPresenterCommon(HomeTabSubWidget):
self.instrument_observer = GenericObserver(self.handle_instrument_changed)
self.fit_observer = GenericObserverWithArgPassing(self.handle_fit_completed)
self.fit_removed_observer = GenericObserverWithArgPassing(self.handle_fit_removed)
self.plot_guess_observer = GenericObserverWithArgPassing(self.handle_fit_completed)
self.rebin_options_set_observer = GenericObserver(self.handle_rebin_options_changed)
self.plot_type_changed_notifier = GenericObservable()
def _setup_view_connections(self):
self._view.on_plot_tiled_checkbox_changed(self.handle_plot_tiled_state_changed)
......@@ -112,6 +116,7 @@ class PlotWidgetPresenterCommon(HomeTabSubWidget):
workspace_list, indices = self._model.get_workspace_list_and_indices_to_plot(self._view.is_raw_plot(),
self._view.get_plot_type())
self._figure_presenter.plot_workspaces(workspace_list, indices, hold_on=False, autoscale=True)
self.plot_type_changed_notifier.notify_subscribers(self._view.get_plot_type())
def handle_plot_tiled_state_changed(self):
"""
......@@ -182,9 +187,13 @@ class PlotWidgetPresenterCommon(HomeTabSubWidget):
tiled_by = self._view.tiled_by()
keys = self._model.create_tiled_keys(tiled_by)
self._figure_presenter.create_tiled_plot(keys, tiled_by)
workspace_list, indices = self._model.get_workspace_list_and_indices_to_plot(self._view.is_raw_plot(),
self._view.get_plot_type())
self._figure_presenter.plot_workspaces(workspace_list, indices, hold_on=False, autoscale=False)
return
workspace_list, indices = self._model.get_workspace_and_indices_for_group_or_pair \
(group_or_pair_name, is_raw=True, plot_type=self._view.get_plot_type())
workspace_list, indices = self._model.get_workspace_and_indices_for_group_or_pair(
group_or_pair_name, is_raw=True, plot_type=self._view.get_plot_type())
self._figure_presenter.plot_workspaces(workspace_list, indices, hold_on=True, autoscale=False)
def handle_removed_group_or_pair_to_plot(self, group_or_pair_name: str):
......@@ -197,9 +206,13 @@ class PlotWidgetPresenterCommon(HomeTabSubWidget):
tiled_by = self._view.tiled_by()
keys = self._model.create_tiled_keys(tiled_by)
self._figure_presenter.create_tiled_plot(keys, tiled_by)
workspace_list, indices = self._model.get_workspace_list_and_indices_to_plot(self._view.is_raw_plot(),
self._view.get_plot_type())
self._figure_presenter.plot_workspaces(workspace_list, indices, hold_on=False, autoscale=False)
return
workspace_list, indices = self._model.get_workspace_and_indices_for_group_or_pair \
(group_or_pair_name, is_raw=True, plot_type=self._view.get_plot_type())
workspace_list, indices = self._model.get_workspace_and_indices_for_group_or_pair(
group_or_pair_name, is_raw=True, plot_type=self._view.get_plot_type())
self._figure_presenter.remove_workspace_names_from_plot(workspace_list)
def handle_external_plot_requested(self):
......@@ -229,7 +242,7 @@ class PlotWidgetPresenterCommon(HomeTabSubWidget):
workspace_list, indices = self._model.get_fit_workspace_and_indices(fit)
self._figure_presenter.plot_workspaces(workspace_list, indices, hold_on=True, autoscale=False)
def handle_fit_removed(self, fits: list[FitInformation]):
def handle_fit_removed(self, fits: List[FitInformation]):
"""
Handles the removal of a fit which is given as an input to the function
:param fits: A list of fits to remove from the plot
......
......@@ -7,13 +7,13 @@
from qtpy import QtWidgets
from mantidqt.utils.qt import load_ui
from Muon.GUI.Common.plotting_widget.plotting_widget_view_interface import PlottingWidgetViewInterface
from Muon.GUI.Common.plot_widget.plot_widget_view_interface import PlotWidgetViewInterface
import Muon.GUI.Common.message_box as message_box
ui_plotting_view, _ = load_ui(__file__, "plotting_widget_view.ui")
class PlotWidgetView1(QtWidgets.QWidget, PlottingWidgetViewInterface, ui_plotting_view):
class PlotWidgetView(QtWidgets.QWidget, PlotWidgetViewInterface, ui_plotting_view):
@staticmethod
def warning_popup(message):
......
......@@ -15,7 +15,7 @@ class PlottingWidgetViewMeta(type(QtWidgets.QWidget), ABCMeta):
pass
class PlottingWidgetViewInterface(metaclass=PlottingWidgetViewMeta):
class PlotWidgetViewInterface(metaclass=PlottingWidgetViewMeta):
@abstractmethod
def setup_plot_type_options(self, options: List[str]):
......
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2020 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
......@@ -14,7 +14,7 @@ else:
NavigationToolbar2QT as NavigationToolbar)
class DockablePlotToolbar(NavigationToolbar):
class PlotToolbar(NavigationToolbar):
def __init__(self, figure_canvas, parent=None):
self.toolitems = (('Home', 'Reset original view', 'home', 'home'),
('Back', 'Back to previous view', 'back', 'back'),
......
......@@ -5,17 +5,18 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from typing import List
from MultiPlotting.QuickEdit.quickEdit_presenter import QuickEditPresenter
from Muon.GUI.Common.plotting_widget.plotting_canvas_model import PlottingCanvasModel
from Muon.GUI.Common.plotting_widget.plotting_canvas_presenter_interface import PlottingCanvasPresenterInterface
from Muon.GUI.Common.plotting_widget.plotting_canvas_view import PlottingCanvasView
from Muon.GUI.Common.plot_widget.plotting_canvas.plotting_canvas_model import PlottingCanvasModel
from Muon.GUI.Common.plot_widget.plotting_canvas.plotting_canvas_presenter_interface import \
PlottingCanvasPresenterInterface
from Muon.GUI.Common.plot_widget.plotting_canvas.plotting_canvas_view_interface import PlottingCanvasViewInterface
from mantid import AnalysisDataService
class PlottingCanvasPresenter(PlottingCanvasPresenterInterface):
def __init__(self, view: PlottingCanvasView, model: PlottingCanvasModel, options_presenter: QuickEditPresenter):
def __init__(self, view: PlottingCanvasViewInterface, model: PlottingCanvasModel,
options_presenter: QuickEditPresenter):
self._view = view
self._model = model
self._options_view = None
......
......@@ -39,7 +39,7 @@ class PlottingCanvasPresenterInterface(abc.ABC):
pass
@abc.abstractmethod
def create_tiled_plot(self, keys: list[str], tiled_by: str):
def create_tiled_plot(self, keys: List[str], tiled_by: str):
"""Creates a blank tiled plot specified by the keys and tiled by type
:param keys: A list of keys which will be used to label and categorize each tile
:param tiled_by: A string which states how the tiles are arranged (can be either by Groups or Runs)
......
......@@ -8,9 +8,9 @@ from typing import List
from matplotlib.container import ErrorbarContainer
from qtpy import QtWidgets
from Muon.GUI.Common.plotting_widget.dockable_plot_toolbar import DockablePlotToolbar
from Muon.GUI.Common.plotting_widget.plotting_canvas_model import WorkspacePlotInformation
from Muon.GUI.Common.plotting_widget.plotting_canvas_view_interface import PlottingCanvasViewInterface, PlottingViewMeta
from Muon.GUI.Common.plot_widget.plotting_canvas.plot_toolbar import PlotToolbar
from Muon.GUI.Common.plot_widget.plotting_canvas.plotting_canvas_model import WorkspacePlotInformation
from Muon.GUI.Common.plot_widget.plotting_canvas.plotting_canvas_view_interface import PlottingCanvasViewInterface
from mantid import AnalysisDataService
from mantid.plots import legend_set_draggable, MantidAxes
from mantid.plots.plotfunctions import get_plot_fig
......@@ -42,7 +42,7 @@ class PlottingCanvasView(QtWidgets.QWidget, PlottingCanvasViewInterface):
# create the figure
self.fig = Figure()
self.fig.canvas = FigureCanvas(self.fig)
self.toolBar = DockablePlotToolbar(self.fig.canvas, self)
self.toolBar = PlotToolbar(self.fig.canvas, self)
# Create a set of Mantid axis for the figure
self.fig, axes = get_plot_fig(overplot=False, ax_properties=None, axes_num=1,
......
......@@ -6,10 +6,8 @@
# SPDX - License - Identifier: GPL - 3.0 +
import abc
from typing import List
from qtpy import QtWidgets
from Muon.GUI.Common.plotting_widget.plotting_canvas_model import WorkspacePlotInformation
from Muon.GUI.Common.plot_widget.plotting_canvas.plotting_canvas_model import WorkspacePlotInformation
# This metaclass is required in order to implement the (strict) interface for the QtWidget
......
......@@ -7,9 +7,9 @@
from typing import List
from MultiPlotting.QuickEdit.quickEdit_widget import QuickEditWidget
from Muon.GUI.Common.plotting_widget.plotting_canvas_model import PlottingCanvasModel
from Muon.GUI.Common.plotting_widget.plotting_canvas_presenter import PlottingCanvasPresenter
from Muon.GUI.Common.plotting_widget.plotting_canvas_view import PlottingCanvasView
from Muon.GUI.Common.plot_widget.plotting_canvas.plotting_canvas_model import PlottingCanvasModel
from Muon.GUI.Common.plot_widget.plotting_canvas.plotting_canvas_presenter import PlottingCanvasPresenter
from Muon.GUI.Common.plot_widget.plotting_canvas.plotting_canvas_view import PlottingCanvasView
class PlottingCanvasWidget(object):
......
......@@ -4,7 +4,7 @@
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from qtpy import QtWidgets, QtCore
from qtpy import QtWidgets, QtCore, QtGui
class PlottingDockWidget(QtWidgets.QDockWidget):
......@@ -19,11 +19,3 @@ class PlottingDockWidget(QtWidgets.QDockWidget):
self.dockable_plot_widget = plotting_widget
# set the widget for this dockable plot window
self.setWidget(self.dockable_plot_widget)
self.dockLocationChanged.connect(self.window_dock_status_changed)
# this function makes the plot rescale after being docked or un-docked,
# to avoid the x labels, y labels and title disappearing upon this action
def window_dock_status_changed(self, area):
pass
#self.dockable_plot_widget.get_fig().tight_layout()
# 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 & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
import numpy as np
from mantid.api import AnalysisDataService
from matplotlib.container import ErrorbarContainer
import matplotlib.pyplot as plt
legend_text_size = 7
class PlotWidgetModel(object):
def __init__(self):
self._plotted_workspaces = []
self._plotted_workspaces_inverse_binning = {}
self._plotted_fit_workspaces = []
self.tiled_plot_positions = {}
# ------------------------------------------------------------------------------------------------------------------
# Properties
# ------------------------------------------------------------------------------------------------------------------
@property
def plotted_workspaces(self):
"""
A list of the plotted workspaces in the figure
"""
return self._plotted_workspaces
@property
def plotted_workspaces_inverse_binning(self):
return self._plotted_workspaces_inverse_binning
@property
def plotted_fit_workspaces(self):
"""
A list of the plotted fit workspaces in the figure
"""
return self._plotted_fit_workspaces
# ------------------------------------------------------------------------------------------------------------------
# Setters
# ------------------------------------------------------------------------------------------------------------------
@plotted_workspaces.setter
def plotted_workspaces(self, workspaces):
self._plotted_workspaces = workspaces
@plotted_workspaces_inverse_binning.setter
def plotted_workspaces_inverse_binning(self, value):
self._plotted_workspaces_inverse_binning = value
@plotted_fit_workspaces.setter
def plotted_fit_workspaces(self, workspaces):
self._plotted_fit_workspaces = workspaces
# ------------------------------------------------------------------------------------------------------------------
# Helper to add and remove from stored workspace lists
# ------------------------------------------------------------------------------------------------------------------
def add_workspace_to_plotted_workspaces(self, workspace_name):
if workspace_name not in self.plotted_workspaces:
self._plotted_workspaces.append(workspace_name)
def remove_workspaces_from_plotted_workspaces(self, workspace_name):
if workspace_name in self.plotted_workspaces:
self._plotted_workspaces.remove(workspace_name)
def add_workspace_to_plotted_fit_workspaces(self, workspace_name):
if workspace_name not in self.plotted_fit_workspaces:
self._plotted_fit_workspaces.append(workspace_name)
def remove_workspaces_from_plotted_fit_workspaces(self, workspace_name):
if workspace_name in self.plotted_fit_workspaces:
self._plotted_fit_workspaces.remove(workspace_name)
# ------------------------------------------------------------------------------------------------------------------
# Plotting
# ------------------------------------------------------------------------------------------------------------------
def add_workspace_to_plot(self, ax, workspace_name, workspace_indices, errors, plot_kwargs):
"""
Adds a plot line to the specified axis
:param ax: Axis to plot the workspace on
:param workspace_name: Name of workspace to get plot data from
:param workspace_indices: workspace indices to plot from workspace
:param errors: Plotting workspace errors
:param plot_kwargs, arguments to Mantid axis plotting
:return:
"""
# check workspace exists -
# retrieveWorkspaces expects a list of workspace names
try:
workspace = AnalysisDataService.Instance().retrieveWorkspaces([workspace_name], unrollGroups=True)
except RuntimeError:
return
self._do_single_plot(ax, workspace, workspace_indices, errors,
plot_kwargs)
self._update_legend(ax)
def remove_workspace_from_plot(self, workspace_name, axes):
"""
Remove workspace from plot
:param workspace_name: Name of workspace to remove from plot
:param axes: the axes which may contain the workspace
:return:
"""
if workspace_name not in self.plotted_workspaces + self.plotted_fit_workspaces:
return
try:
workspace = AnalysisDataService.Instance().retrieve(workspace_name)
except RuntimeError:
return
for i in range(len(axes)):
ax = axes[i]
ax.remove_workspace_artists(workspace)
self._update_legend(ax)
self.plotted_workspaces = [item for item in self.plotted_workspaces if item != workspace_name]
self.plotted_fit_workspaces = [item for item in self.plotted_fit_workspaces if item != workspace_name]
if workspace_name in self.plotted_workspaces_inverse_binning:
self.plotted_workspaces_inverse_binning.pop(workspace_name)
def workspace_deleted_from_ads(self, workspace, axes):
"""
Remove a workspace which was deleted in the ads from the plot
:param workspace: Workspace object to remove from plot
:param axes: the axes which may contain the workspace
:return:
"""
workspace_name = workspace.name()
if workspace_name not in self.plotted_workspaces + self.plotted_fit_workspaces:
return
for i in range(len(axes)):
ax = axes[i]
ax.remove_workspace_artists(workspace)
self._update_legend(ax)
self.plotted_workspaces = [item for item in self.plotted_workspaces if item != workspace_name]
self.plotted_fit_workspaces = [item for item in self.plotted_fit_workspaces if item != workspace_name]
if workspace_name in self.plotted_workspaces_inverse_binning:
self.plotted_workspaces_inverse_binning.pop(workspace_name)
def _do_single_plot(self, ax, workspaces, indices, errors, plot_kwargs):
plot_fn = ax.errorbar if errors else ax.plot
for ws in workspaces:
for index in indices:
plot_kwargs['wkspIndex'] = index
plot_fn(ws, **plot_kwargs)
def replace_workspace_plot(self, workspace_name, axis):
"""
Replace workspace from plot
:param workspace_name: Name of workspace to update in plot
:param axis: the axis that contains the workspace
:return:
"""
try:
workspace = AnalysisDataService.Instance().retrieve(workspace_name)
except RuntimeError:
return
axis.replace_workspace_artists(workspace)
def replot_workspace(self, workspace_name, axis, errors, plot_kwargs):
"""
Replot a workspace with different kwargs, and error flag
with the intention of keeping the rest of the model unchanged
:param workspace_name: Name of workspace to update in plot
:param axis: the axis that contains the workspace
:param errors: Plotting with errors
:param plot_kwargs: kwargs to the plotting
:return:
"""
artist_info = axis.tracked_workspaces[workspace_name]
for ws_artist in artist_info:
for artist in ws_artist._artists:
# if the artist in an errorbarCotainer, the first object
# in the tuple will contain the matplotlib line object
if isinstance(artist, ErrorbarContainer):
color = artist[0].get_color()
else:
color = artist.get_color()
plot_kwargs["color"] = color
axis.replot_artist(artist, errors, **plot_kwargs)
self._update_legend(axis)
def clear_plot_model(self, axes):
self._remove_all_data_workspaces_from_plot(axes)
self.plotted_workspaces = []
self.plotted_workspaces_inverse_binning = {}
self.plotted_fit_workspaces = []
def remove_fit_workspace(self, fit_workspace, axes):
if fit_workspace in self.plotted_fit_workspaces:
self.remove_workspace_from_plot(fit_workspace, axes)
def _remove_all_data_workspaces_from_plot(self, axes):
workspaces_to_remove = self.plotted_workspaces
for workspace in workspaces_to_remove:
self.remove_workspace_from_plot(workspace, axes)
workspaces_to_remove = self.plotted_fit_workspaces
for workspace in workspaces_to_remove:
self.remove_workspace_from_plot(workspace, axes)
def autoscale_axes(self, axes, xlimits):
ymin, ymax = self._get_autoscale_y_limits(axes, xlimits[0], xlimits[1])
plt.setp(axes, xlim=xlimits, ylim=[ymin, ymax])
return ymin, ymax
def set_axis_xlim(self, axis, xlims):
axis.set_xlim(left=xlims[0], right=xlims[1])
def set_axis_ylim(self, axis, ylims):
axis.set_ylim(ylims[0], ylims[1])
def _get_autoscale_y_limits(self, axes, xmin, xmax):
new_bottom = 1e9
new_top = -1e9
for axis in axes:
axis.set_xlim(left=xmin, right=xmax)
xlim = axis.get_xlim()
ylim = np.inf, -np.inf
for line in axis.lines:
x, y = line.get_data()
start, stop = np.searchsorted(x, xlim)
y_within_range = y[max(start - 1, 0):(stop + 1)]
ylim = min(ylim[0], np.nanmin(y_within_range)), max(ylim[1], np.nanmax(y_within_range))
new_bottom_i = ylim[0] * 1.3 if ylim[0] < 0.0 else ylim[0] * 0.7
new_top_i = ylim[1] * 1.3 if ylim[1] > 0.0 else ylim[1] * 0.7
if new_bottom_i < new_bottom:
new_bottom = new_bottom_i
if new_top_i > new_top:
new_top = new_top_i
return new_bottom, new_top
def _update_legend(self, ax):
handles, _ = ax.get_legend_handles_labels()
if handles:
ax.legend(prop=dict(size=legend_text_size))
else:
ax.legend("")
def get_axes_titles(self, axes):
titles = [None] * len(axes)
for i in range(len(axes)):
titles[i] = axes[i].get_title()
return titles
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment