@@ -118,9 +118,12 @@ def color_palette_table(colors,
118118 return np .c_ [r , g , b ]
119119
120120
121- def levels_with_thresholds (low , high , threshold_low , threshold_high ):
121+ def levels_with_thresholds (low , high , threshold_low , threshold_high , center_palette ):
122122 lt = low + (high - low ) * threshold_low
123123 ht = low + (high - low ) * threshold_high
124+ if center_palette :
125+ ht = max (abs (lt ), abs (ht ))
126+ lt = - max (abs (lt ), abs (ht ))
124127 return lt , ht
125128
126129
@@ -317,6 +320,8 @@ class Outputs:
317320 selected_data = Output ("Selected Data" , Table , default = True )
318321 annotated_data = Output (ANNOTATED_DATA_SIGNAL_NAME , Table )
319322
323+ settings_version = 2
324+
320325 settingsHandler = settings .DomainContextHandler ()
321326
322327 NoPosition , PositionTop , PositionBottom = 0 , 1 , 2
@@ -327,6 +332,7 @@ class Outputs:
327332 gamma = settings .Setting (0 )
328333 threshold_low = settings .Setting (0.0 )
329334 threshold_high = settings .Setting (1.0 )
335+ center_palette = settings .Setting (False )
330336
331337 merge_kmeans = settings .Setting (False )
332338 merge_kmeans_k = settings .Setting (50 )
@@ -447,6 +453,9 @@ def __init__(self):
447453
448454 colorbox .layout ().addLayout (form )
449455
456+ gui .checkBox (colorbox , self , 'center_palette' , 'Center colors at 0' ,
457+ callback = self .update_color_schema )
458+
450459 mergebox = gui .vBox (self .controlArea , "Merge" ,)
451460 gui .checkBox (mergebox , self , "merge_kmeans" , "Merge by k-means" ,
452461 callback = self .update_sorting_examples )
@@ -982,7 +991,7 @@ def setup_scene(self, parts, data):
982991
983992 hw .set_levels (parts .levels )
984993 hw .set_thresholds (self .threshold_low , self .threshold_high )
985- hw .set_color_table (palette )
994+ hw .set_color_table (palette , self . center_palette )
986995 hw .set_show_averages (self .averages )
987996 hw .set_heatmap_data (X_part )
988997
@@ -1057,7 +1066,7 @@ def setup_scene(self, parts, data):
10571066 parts .levels [0 ], parts .levels [1 ], self .threshold_low , self .threshold_high ,
10581067 parent = widget )
10591068
1060- legend .set_color_table (palette )
1069+ legend .set_color_table (palette , self . center_palette )
10611070 legend .setMinimumSize (QSizeF (100 , 20 ))
10621071 legend .setVisible (self .legend )
10631072
@@ -1318,11 +1327,11 @@ def update_color_schema(self):
13181327 palette = self .color_palette ()
13191328 for heatmap in self .heatmap_widgets ():
13201329 heatmap .set_thresholds (self .threshold_low , self .threshold_high )
1321- heatmap .set_color_table (palette )
1330+ heatmap .set_color_table (palette , self . center_palette )
13221331
13231332 for legend in self .legend_widgets ():
13241333 legend .set_thresholds (self .threshold_low , self .threshold_high )
1325- legend .set_color_table (palette )
1334+ legend .set_color_table (palette , self . center_palette )
13261335
13271336 def update_sorting_examples (self ):
13281337 self .update_heatmaps ()
@@ -1601,6 +1610,7 @@ def __init__(self, parent=None, data=None, **kwargs):
16011610
16021611 self .__levels = None
16031612 self .__threshold_low , self .__threshold_high = 0. , 1.
1613+ self .__center_palette = False
16041614 self .__colortable = None
16051615 self .__data = data
16061616
@@ -1677,8 +1687,9 @@ def set_show_averages(self, show):
16771687 self .layout ().invalidate ()
16781688 self .update ()
16791689
1680- def set_color_table (self , table ):
1690+ def set_color_table (self , table , center ):
16811691 self .__colortable = table
1692+ self .__center_palette = center
16821693 self ._update_pixmap ()
16831694 self .update ()
16841695
@@ -1699,7 +1710,8 @@ def _update_pixmap(self):
16991710 lut = None
17001711
17011712 ll , lh = self .__levels
1702- ll , lh = levels_with_thresholds (ll , lh , self .__threshold_low , self .__threshold_high )
1713+ ll , lh = levels_with_thresholds (ll , lh , self .__threshold_low , self .__threshold_high ,
1714+ self .__center_palette )
17031715
17041716 argb , _ = pg .makeARGB (
17051717 self .__data , lut = lut , levels = (ll , lh ))
@@ -2058,6 +2070,7 @@ def __init__(self, low, high, threshold_low, threshold_high, parent=None):
20582070 self .high = high
20592071 self .threshold_low = threshold_low
20602072 self .threshold_high = threshold_high
2073+ self .center_palette = False
20612074 self .color_table = None
20622075
20632076 layout = QGraphicsLinearLayout (Qt .Vertical )
@@ -2084,8 +2097,9 @@ def __init__(self, low, high, threshold_low, threshold_high, parent=None):
20842097 layout .addItem (self .__pixitem )
20852098 self .__update ()
20862099
2087- def set_color_table (self , color_table ):
2100+ def set_color_table (self , color_table , center ):
20882101 self .color_table = color_table
2102+ self .center_palette = center
20892103 self .__update ()
20902104
20912105 def set_thresholds (self , threshold_low , threshold_high ):
@@ -2097,7 +2111,8 @@ def __update(self):
20972111 data = np .linspace (self .low , self .high , num = 1000 )
20982112 data = data .reshape ((1 , - 1 ))
20992113 ll , lh = levels_with_thresholds (self .low , self .high ,
2100- self .threshold_low , self .threshold_high )
2114+ self .threshold_low , self .threshold_high ,
2115+ self .center_palette )
21012116 argb , _ = pg .makeARGB (data , lut = self .color_table ,
21022117 levels = (ll , lh ))
21032118 qimg = pg .makeQImage (argb , transpose = False )
0 commit comments