-
Notifications
You must be signed in to change notification settings - Fork 126
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
Allow users to register custom matplotlib colormaps #38587
Allow users to register custom matplotlib colormaps #38587
Conversation
Would it be possible to provide a bit more information about the work? Unfortunately unless we work at ORNL we can't access the linked issue. As this is functionality that is not ORNL specific there is wider interest. |
User's previously could modify the listed colormaps in Matplotlib by overwriting one of the default maps using their own custom map file of RGB values. Matplotlib now does not let the maps to be overwritten, so this doesn't work. This issue makes it possible to define a separate custom map that can be read into sliceviewer. |
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
from matplotlib import cm
from mantid.simpleapi import *
# Load map file
Cmap_Name = 'MDF' # Colormap name
Loaded_Cmap = np.loadtxt('/HFIR/HB2C/shared/WANDscripts/colormaps/MDF.map')/255
# Register the loaded Colormap
Listed_CustomCmap = ListedColormap(Loaded_Cmap, name=Cmap_Name)
# Create and register the reverse colormap
Listed_CustomCmap_r = ListedColormap(Loaded_Cmap[::-1,:], name=(Cmap_Name + '_r') )
cm.register_cmap(name=Cmap_Name, cmap=Listed_CustomCmap, override_builtin=True)
cm.register_cmap(name=(Cmap_Name + '_r'), cmap= Listed_CustomCmap_r, override_builtin=True)
ws = CreateMDWorkspace(Dimensions='3',
EventType='MDEvent',
Extents='-10,10,-5,5,-1,1',
Names='Q_lab_x,Q_lab_y,Q_lab_z',
Units='1\A,1\A,1\A')
FakeMDEventData(ws, UniformParams="1000000") works well. Thank you for this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description of work
This apparently work previously but stopped working at some point. The problem is that the list of available colormaps is initialized once when ColorbarWidget is first imported and we have users that like loaded register new colormaps in their scripts. This change makes it work again.
Summary of work
Fixes 8690: [Defect] Add MDF colormap to workbench and slice viewer
Further detail of work
To test:
then open
ws
with Sliceviewer and check ifCUSTOM_MAP
is now one of the available Colormaps.This will throw an error if you select the
Reverse
option unless a map namedCUSTOM_MAP_r
is also added.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
Functional Tests
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.