Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing overlapping labels in subplots from Fit Script Generator #38823

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

warunawickramasingha
Copy link
Contributor

@warunawickramasingha warunawickramasingha commented Feb 11, 2025

Description of work

There had been an overlap of subplots labels generated from the Fit Script Generator Interface and this PR is fixing that.

Fixes #37375.

To test:

  1. Open the Mantid Workbench and run below script
from mantid.simpleapi import *
Load(Filename=r'irs26176_graphite002_red.nxs', OutputWorkspace='irs26176_red')
  1. Select the Fit Script Generator
  2. Click on Add Domain
  3. Add a suitable workspace e.g. ‘irs26176_red’ from ISIS Training data
  4. Add workspace Indices e.g. '0-4'
  5. Right click on the Function Browser and add a Lorentzian function
  6. Change the Amplitude parameter values to 1.5
  7. Click Generate Script to Clipboard, and then paste into an empty python script window
  8. Run the script to generate the plots
  9. When the plot window is maximized, the labels should not overlap each other.
  • Plots before the fix:
    before

  • Plots after the fix:
    after

Note: Calling fig.tight_layout() before fig.subplots_adjust() could have fixed the issue. But it makes each sub plot looks smaller when the number of subplots are increased and hence it was not used.


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.

@warunawickramasingha warunawickramasingha added this to the Release 6.13 milestone Feb 11, 2025
@warunawickramasingha warunawickramasingha added Bug Issues and pull requests that are regressions or would be considered a bug by users (e.g. crashing) Maintenance Unassigned issues to be addressed in the next maintenance period. labels Feb 11, 2025
@warunawickramasingha warunawickramasingha force-pushed the 37375_fitscript_gen_subplots branch from 943b041 to 98bbed5 Compare February 12, 2025 14:16
@jhaigh0 jhaigh0 self-assigned this Feb 12, 2025
@warunawickramasingha warunawickramasingha changed the title 37375 fitscript gen subplots Fixing overlapping labels in subplots from Fit Script Generator Feb 13, 2025
@jhaigh0
Copy link
Contributor

jhaigh0 commented Feb 18, 2025

I think we could solve this in a more universal way.

It seems to me that the plot titles themselves could be shortened, they contain a lot of redundant information. So Output_Fitiris26176_red1_Workspace could really just be iris26176_red1. In fact, a better solution might be to label the data on the legends with iris26176_red1 rather than just Data.
Doing this will remove the need for subplot titles. I think also setting the layout as tight would be good to stop collisions at smaller scales, if you move the title information to the legends then there will be no issue of the plots becoming too small.

@warunawickramasingha
Copy link
Contributor Author

warunawickramasingha commented Feb 19, 2025

I think we could solve this in a more universal way.

It seems to me that the plot titles themselves could be shortened, they contain a lot of redundant information. So Output_Fitiris26176_red1_Workspace could really just be iris26176_red1. In fact, a better solution might be to label the data on the legends with iris26176_red1 rather than just Data. Doing this will remove the need for subplot titles. I think also setting the layout as tight would be good to stop collisions at smaller scales, if you move the title information to the legends then there will be no issue of the plots becoming too small.

Thanks for the review @jhaigh0. I have applied the suggested change and just had a look how it would look like for an example when there are 6 plots with tight_layout. Unfortunately, it does not look good.
image

Instead, we can keep the titles replaced with the better legends as you've suggested and have fig.subplots_adjust(hspace=0, wspace=0.5) without doing tight_layout which will generate a plot like the one below.
image

unless you could suggest a different approach, I can apply this change if you are happy.

@jhaigh0
Copy link
Contributor

jhaigh0 commented Feb 19, 2025

@warunawickramasingha
You could try taking the legend out of the layout consideration, as we do in mantid internal plots.

legend = ax.legeng(args..)
legend.set_in_layout(false)

That way you should still be able to use tight layout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues and pull requests that are regressions or would be considered a bug by users (e.g. crashing) Maintenance Unassigned issues to be addressed in the next maintenance period.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fit Script Generator subplots overlap
2 participants