Skip to content

Conversation

KyleQianliMa
Copy link
Contributor

Description of work

This PR handles errors that arises from crosshair functions interacting with mantid. PR 39491

The issue is when changing normalisation and error bars, the figure object is treated as mantid object such as mantidaxes with key word arg such as "workspaces". The crosshair, at the moment, is implemented purely as matplotlib object and would cause error and crash the plot. A quick fix is to catch these errors.

In the long term, we will integrate the crosshair as a mantid specific object for handling mantid data.

Summary of work

Fixes #39592 .

Further detail of work

To test:

Run the instructions in the smoking tests, specifically focusing on changing normalisation and error bars while crosshair is open.

This script can be used to quickly open the plot pannel for testing:

# import mantid algorithms, numpy and matplotlib
from mantid.simpleapi import *
import matplotlib.pyplot as plt
from mantid.plots.utility import MantidAxType

MAR11060 = Load('MAR11060')

fig, axes = plt.subplots(edgecolor='#ffffff', ncols=2, nrows=2, num='MAR11060-1', subplot_kw={'projection': 'mantid'})
axes[0][0].plot(MAR11060, color='#1f77b4', label='MAR11060: spec 1', wkspIndex=0)
axes[0][0].set_xlabel('Time-of-flight ($\\mu s$)')
axes[0][0].set_ylabel('Counts ($\\mu s$)$^{-1}$')
legend = axes[0][0].legend(fontsize=8.0) #.set_draggable(True).legend # uncomment to set the legend draggable

axes[0][1].plot(MAR11060, color='#1f77b4', label='MAR11060: spec 2', wkspIndex=1)
axes[0][1].set_xlabel('Time-of-flight ($\\mu s$)')
axes[0][1].set_ylabel('Counts ($\\mu s$)$^{-1}$')
legend = axes[0][1].legend(fontsize=8.0) #.set_draggable(True).legend # uncomment to set the legend draggable

axes[1][0].plot(MAR11060, color='#1f77b4', label='MAR11060: spec 3', wkspIndex=2)
axes[1][0].set_xlabel('Time-of-flight ($\\mu s$)')
axes[1][0].set_ylabel('Counts ($\\mu s$)$^{-1}$')
legend = axes[1][0].legend(fontsize=8.0) #.set_draggable(True).legend # uncomment to set the legend draggable

axes[1][1].plot(MAR11060, color='#1f77b4', label='MAR11060: spec 4', wkspIndex=3)
axes[1][1].set_xlabel('Time-of-flight ($\\mu s$)')
axes[1][1].set_ylabel('Counts ($\\mu s$)$^{-1}$')
legend = axes[1][1].legend(fontsize=8.0) #.set_draggable(True).legend # uncomment to set the legend draggable

fig.show()

Reviewer

Please comment on the points listed below (full description).
Your comments will be used as part of the gatekeeper process, so please comment clearly on what you have checked during your review. If changes are made to the PR during the review process then your final comment will be the most important for gatekeepers. In this comment you should make it clear why any earlier review is still valid, or confirm that all requested changes have been addressed.

Code Review

  • Is the code of an acceptable quality?
  • Does the code conform to the coding standards?
  • Are the unit tests small and test the class in isolation?
  • If there is GUI work does it follow the GUI standards?
  • If there are changes in the release notes then do they describe the changes appropriately?
  • Do the release notes conform to the release notes guide?

Functional Tests

  • Do changes function as described? Add comments below that describe the tests performed?
  • Do the changes handle unexpected situations, e.g. bad input?
  • Has the relevant (user and developer) documentation been added/updated?

Does everything look good? Mark the review as Approve. A member of @mantidproject/gatekeepers will take care of it.

Gatekeeper

If you need to request changes to a PR then please add a comment and set the review status to "Request changes". This will stop the PR from showing up in the list for other gatekeepers.

@KyleQianliMa KyleQianliMa self-assigned this Jun 27, 2025
@KyleQianliMa KyleQianliMa added Framework Issues and pull requests related to components in the Framework ORNL Team Issues and pull requests managed by the ORNL development team labels Jun 27, 2025
@KyleQianliMa KyleQianliMa added this to the Release 6.13 milestone Jun 27, 2025
@sf1919 sf1919 added the High Priority An issue or pull request that if not addressed is severe enough to postponse a release. label Jun 27, 2025
@KyleQianliMa KyleQianliMa linked an issue Jun 27, 2025 that may be closed by this pull request
Copy link
Member

@peterfpeterson peterfpeterson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does indeed work as advertised. I tried with normal line plots.

@KedoKudo KedoKudo merged commit 6a5ee26 into release-next Jun 27, 2025
10 checks passed
@KedoKudo KedoKudo deleted the crosshair_bugfix_release_next branch June 27, 2025 21:05
@jhaigh0
Copy link
Contributor

jhaigh0 commented Jun 30, 2025

Thanks for fixing those bugs we found with the plot crosshair, I don't envy you adding anything to the plotting interface, it's a minefield.
Unfortunately we found something else this morning, when you double-click with the crosshair toggled on, the curve settings open. In the list of curves are two curves called child_<number> which are the vertical and horizontal components of the crosshair. If you try and change any settings for one of the crosshair curves, when you click apply you get an error. If you 'continue working' you end up with just half a crosshair (attempting to toggle it off in this state also gives an error).
I think probably as a workaround you want to just filter that list of curves in the plot options so that the user can't mess around with them (I think that would be done here). Similar problems happen if you open them, remove one of crosshair curves, and try to toggle them on.

thomashampson added a commit that referenced this pull request Jul 2, 2025
…39611)

We found a bug with the new crosshair plotting feature where its lines
would show up in the plot settings (see comment
#39598 (comment))

This pr gives the crosshair lines the label `'_nolegend_'` which means
they are ignored by the plot settings.


Co-authored-by: thomashampson <thomas.hampson@stfc.ac.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues and pull requests related to components in the Framework High Priority An issue or pull request that if not addressed is severe enough to postponse a release. ORNL Team Issues and pull requests managed by the ORNL development team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plot crosshair interferes with normalisation
5 participants