diff --git a/docs/source/release/v5.1.0/mantidworkbench.rst b/docs/source/release/v5.1.0/mantidworkbench.rst index 8a82337394021d6ee1ddeafd70fd5631239f029e..0a42cd9274139d19b39e8823dede834d455d6173 100644 --- a/docs/source/release/v5.1.0/mantidworkbench.rst +++ b/docs/source/release/v5.1.0/mantidworkbench.rst @@ -8,6 +8,8 @@ MantidWorkbench Changes Improvements ############ +- Tile plots are now reloaded correctly by project recovery. + Bugfixes ######## diff --git a/qt/python/mantidqt/project/plotsloader.py b/qt/python/mantidqt/project/plotsloader.py index 30505f16ee118ad6e51fc158c92b527df0f2765e..83cf63be9862a9808e5d7a8bbf0eb7d95df2a0d3 100644 --- a/qt/python/mantidqt/project/plotsloader.py +++ b/qt/python/mantidqt/project/plotsloader.py @@ -17,10 +17,10 @@ from matplotlib import axis, ticker # noqa from mantid import logger from mantid.api import AnalysisDataService as ADS from mantid.plots.legend import LegendProperties +from mantid.plots.plotfunctions import create_subplots # Constants set in workbench.plotting.functions but would cause backwards reliability from mantidqt.plotting.functions import pcolormesh - SUBPLOT_WSPACE = 0.5 SUBPLOT_HSPACE = 0.5 @@ -40,7 +40,8 @@ class PlotsLoader(object): # Catch all errors in here so it can fail silently-ish if isinstance(e, KeyboardInterrupt): raise KeyboardInterrupt(str(e)) - logger.warning("A plot was unable to be loaded from the save file. Error: " + str(e)) + logger.warning("A plot was unable to be loaded from the save file. Error: " + + str(e)) def make_fig(self, plot_dict, create_plot=True): """ @@ -48,9 +49,7 @@ class PlotsLoader(object): :param plot_dict: dictionary; A dictionary of various items intended to recreate a figure :param create_plot: Bool; whether or not to make the plot, or to return the figure. :return: matplotlib.figure; Only returns if create_plot=False - """ - import matplotlib.pyplot as plt - # Grab creation arguments + """ # Grab creation arguments creation_args = plot_dict["creationArguments"] if len(creation_args) == 0: @@ -59,21 +58,16 @@ class PlotsLoader(object): "The original plot title was: {}".format(plot_dict["label"])) return - # Make a copy so it can be applied to the axes, of the plot once created. - creation_args_copy = copy.deepcopy(creation_args[0]) - - # Make initial plot - fig, ax = plt.subplots(subplot_kw={'projection': 'mantid'}) - - # If an overplot is necessary plot onto the same figure - for cargs in creation_args[0]: - if "workspaces" in cargs: - workspace_name = cargs.pop('workspaces') - workspace = ADS.retrieve(workspace_name) - self.plot_func(workspace, ax, ax.figure, cargs) - - # Make sure that the axes gets it's creation_args as loading doesn't add them - ax.creation_args = creation_args_copy + fig, axes_matrix, _, _ = create_subplots(len(creation_args)) + axes_list = axes_matrix.flatten().tolist() + for ax, cargs_list in zip(axes_list, creation_args): + creation_args_copy = copy.deepcopy(cargs_list) + for cargs in cargs_list: + if "workspaces" in cargs: + workspace_name = cargs.pop("workspaces") + workspace = ADS.retrieve(workspace_name) + self.plot_func(workspace, ax, ax.figure, cargs) + ax.creation_args = creation_args_copy # Update the fig fig._label = plot_dict["label"] @@ -102,10 +96,20 @@ class PlotsLoader(object): if "cmap" in creation_arg: creation_arg["cmap"] = getattr(matplotlib.cm, creation_arg["cmap"]) - function_dict = {"plot": axes.plot, "scatter": axes.scatter, "errorbar": axes.errorbar, - "pcolor": axes.pcolor, "pcolorfast": axes.pcolorfast, "pcolormesh": pcolormesh, - "imshow": pcolormesh, "contour": axes.contour, "contourf": axes.contourf, - "tripcolor": axes.tripcolor, "tricontour": axes.tricontour, "tricontourf": axes.tricontourf} + function_dict = { + "plot": axes.plot, + "scatter": axes.scatter, + "errorbar": axes.errorbar, + "pcolor": axes.pcolor, + "pcolorfast": axes.pcolorfast, + "pcolormesh": pcolormesh, + "imshow": pcolormesh, + "contour": axes.contour, + "contourf": axes.contourf, + "tripcolor": axes.tripcolor, + "tricontour": axes.tricontour, + "tricontourf": axes.tricontourf + } func = function_dict[function_to_call] # Plotting is done via an Axes object unless a colorbar needs to be added @@ -124,6 +128,8 @@ class PlotsLoader(object): except IndexError as e: if not self.color_bar_remade: raise IndexError(e) + except KeyError: + logger.notice("Not adding data to blank axis.") @staticmethod def restore_fig_properties(fig, dic): @@ -178,14 +184,16 @@ class PlotsLoader(object): ax.text(x=dic["position"][0], y=dic["position"][1], s=dic["text"], - fontdict={u'alpha': style_dic["alpha"], - u'color': style_dic["color"], - u'rotation': style_dic["rotation"], - u'fontsize': style_dic["textSize"], - u'zorder': style_dic["zOrder"], - u'usetex': dic["useTeX"], - u'horizontalalignment': style_dic["hAlign"], - u'verticalalignment': style_dic["vAlign"]}) + fontdict={ + u'alpha': style_dic["alpha"], + u'color': style_dic["color"], + u'rotation': style_dic["rotation"], + u'fontsize': style_dic["textSize"], + u'zorder': style_dic["zOrder"], + u'usetex': dic["useTeX"], + u'horizontalalignment': style_dic["hAlign"], + u'verticalalignment': style_dic["vAlign"] + }) @staticmethod def update_lines(ax, line): @@ -301,8 +309,9 @@ class PlotsLoader(object): try: image.axes.set_cmap(cm.get_cmap(dic["cmap"])) except AttributeError as e: - logger.debug("PlotsLoader - The Image accessed did not have an axes with the ability to set the cmap: " - + str(e)) + logger.debug( + "PlotsLoader - The Image accessed did not have an axes with the ability to set the cmap: " + + str(e)) # Redraw image.axes.figure.canvas.draw()