3737)
3838from hexrdgui .utils .tth_distortion import apply_tth_distortion_if_needed
3939
40- FONTSIZE_LABEL = 15
41- FONTSIZE_TICKS = 15
40+ # Increase these font sizes (compared to the global font) by the specified
41+ # amounts.
42+ FONTSIZE_LABEL_INCREASE = 4
43+ FONTSIZE_TICKS_INCREASE = 4
44+
4245
4346class ImageCanvas (FigureCanvas ):
4447
@@ -118,6 +121,42 @@ def setup_connections(self):
118121 def thread_pool (self ):
119122 return QThreadPool .globalInstance ()
120123
124+ @property
125+ def fontsize_label (self ):
126+ return HexrdConfig ().font_size + FONTSIZE_LABEL_INCREASE
127+
128+ @property
129+ def fontsize_ticks (self ):
130+ return HexrdConfig ().font_size + FONTSIZE_TICKS_INCREASE
131+
132+ @property
133+ def label_kwargs (self ):
134+ return {
135+ 'fontsize' : self .fontsize_label ,
136+ 'family' : 'serif' ,
137+ }
138+
139+ @property
140+ def major_tick_kwargs (self ):
141+ return {
142+ 'left' : True ,
143+ 'right' : True ,
144+ 'bottom' : True ,
145+ 'top' : True ,
146+ 'which' : 'major' ,
147+ 'length' : 10 ,
148+ 'labelfontfamily' : 'serif' ,
149+ 'labelsize' : self .fontsize_ticks ,
150+ }
151+
152+ @property
153+ def minor_tick_kwargs (self ):
154+ return {
155+ ** self .major_tick_kwargs ,
156+ 'which' : 'minor' ,
157+ 'length' : 2 ,
158+ }
159+
121160 def __del__ (self ):
122161 # This is so that the figure can be cleaned up
123162 plt .close (self .figure )
@@ -1044,34 +1083,16 @@ def finish_show_polar(self, iviewer):
10441083 self .axis .yaxis .set_minor_locator (AutoMinorLocator ())
10451084
10461085 self .axis .xaxis .set_major_locator (PolarXAxisTickLocator (self ))
1047- self .axis .xaxis .set_minor_locator (PolarXAxisMinorTickLocator (self ))
1048-
1049- kwargs = {
1050- 'left' : True ,
1051- 'right' : True ,
1052- 'bottom' : True ,
1053- 'top' : True ,
1054- 'which' : 'major' ,
1055- 'length' : 10 ,
1056- 'labelfontfamily' : 'serif' ,
1057- 'labelsize' : FONTSIZE_TICKS ,
1058- }
1059- self .axis .tick_params (** kwargs )
1060-
1061- kwargs ['which' ] = 'minor'
1062- kwargs ['length' ] = 2
1063- self .axis .tick_params (** kwargs )
1064-
1065- self .axis .tick_params (
1066- bottom = True , top = True , which = 'major' , length = 8 )
1067- self .axis .tick_params (
1068- bottom = True , top = True , which = 'minor' , length = 2 )
1086+ self .axis .xaxis .set_minor_locator (
1087+ PolarXAxisMinorTickLocator (self )
1088+ )
1089+ self .axis .tick_params (** self .major_tick_kwargs )
1090+ self .axis .tick_params (** self .minor_tick_kwargs )
10691091
10701092 # Do not allow the axis to autoscale, which could happen if
10711093 # overlays are drawn out-of-bounds
10721094 self .axis .autoscale (False )
1073- self .axis .set_ylabel (
1074- r'$\eta$ [deg]' , fontsize = FONTSIZE_LABEL , family = 'serif' )
1095+ self .axis .set_ylabel (r'$\eta$ [deg]' , ** self .label_kwargs )
10751096 self .axis .label_outer ()
10761097 else :
10771098 rescale_image = False
@@ -1091,7 +1112,7 @@ def finish_show_polar(self, iviewer):
10911112 HexrdConfig ().last_unscaled_azimuthal_integral_data = unscaled
10921113
10931114 self .azimuthal_integral_axis = axis
1094- axis .set_ylabel (r'Azimuthal Average' , fontsize = FONTSIZE_LABEL , family = 'serif' )
1115+ axis .set_ylabel (r'Azimuthal Average' , ** self . label_kwargs )
10951116 self .update_azimuthal_plot_overlays ()
10961117 self .update_wppf_plot ()
10971118
@@ -1105,24 +1126,13 @@ def finish_show_polar(self, iviewer):
11051126 axis .yaxis .set_minor_locator (AutoMinorLocator ())
11061127
11071128 axis .xaxis .set_major_locator (PolarXAxisTickLocator (self ))
1108- self .axis .xaxis .set_minor_locator (PolarXAxisMinorTickLocator (self ))
1129+ self .axis .xaxis .set_minor_locator (
1130+ PolarXAxisMinorTickLocator (self )
1131+ )
11091132
11101133 # change property of ticks
1111- kwargs = {
1112- 'left' : True ,
1113- 'right' : True ,
1114- 'bottom' : True ,
1115- 'top' : True ,
1116- 'which' : 'major' ,
1117- 'length' : 10 ,
1118- 'labelfontfamily' : 'serif' ,
1119- 'labelsize' : FONTSIZE_TICKS ,
1120- }
1121- axis .tick_params (** kwargs )
1122-
1123- kwargs ['which' ] = 'minor'
1124- kwargs ['length' ] = 2
1125- axis .tick_params (** kwargs )
1134+ axis .tick_params (** self .major_tick_kwargs )
1135+ axis .tick_params (** self .minor_tick_kwargs )
11261136
11271137 # add grid lines parallel to x-axis in azimuthal average
11281138 kwargs = {
@@ -1156,7 +1166,7 @@ def finish_show_polar(self, iviewer):
11561166 axis = self .azimuthal_integral_axis
11571167
11581168 # Update the xlabel in case it was modified (via tth distortion)
1159- axis .set_xlabel (self .polar_xlabel , fontsize = FONTSIZE_LABEL , family = 'serif' )
1169+ axis .set_xlabel (self .polar_xlabel , ** self . label_kwargs )
11601170 else :
11611171 if len (self .axes_images ) == 0 :
11621172 self .axis = self .figure .add_subplot (111 )
@@ -1168,14 +1178,13 @@ def finish_show_polar(self, iviewer):
11681178 'interpolation' : 'none' ,
11691179 }
11701180 self .axes_images .append (self .axis .imshow (** kwargs ))
1171- self .axis .set_ylabel (r'$\eta$ [deg]' , fontsize = FONTSIZE_LABEL , family = 'serif' )
1181+ self .axis .set_ylabel (r'$\eta$ [deg]' , ** self . label_kwargs )
11721182 else :
11731183 rescale_image = False
11741184 self .axes_images [0 ].set_data (img )
11751185
11761186 # Update the xlabel in case it was modified (via tth distortion)
1177- self .axis .set_xlabel (self .polar_xlabel , fontsize = FONTSIZE_LABEL , family = 'serif' )
1178-
1187+ self .axis .set_xlabel (self .polar_xlabel , ** self .label_kwargs )
11791188
11801189 if rescale_image :
11811190 self .axis .relim ()
@@ -1275,8 +1284,8 @@ def polar_x_axis_type(self):
12751284
12761285 def on_polar_x_axis_type_changed (self ):
12771286 # Update the x-label
1278- self .azimuthal_integral_axis .set_xlabel (self . polar_xlabel ,
1279- fontsize = FONTSIZE_LABEL , family = 'serif' )
1287+ self .azimuthal_integral_axis .set_xlabel (
1288+ self . polar_xlabel , ** self . label_kwargs )
12801289
12811290 # Still need to draw if the x-label was modified
12821291 self .draw_idle ()
@@ -1784,7 +1793,12 @@ def draw_mask_boundaries(self, axis, det=None):
17841793 delta_eta_est = np .nanmedian (eta_diff )
17851794 tolerance = delta_eta_est * 10
17861795 big_gaps , = np .nonzero (eta_diff > tolerance )
1787- verts [i ] = np .insert (vert , big_gaps + 1 , np .nan , axis = 0 )
1796+ verts [i ] = np .insert (
1797+ vert ,
1798+ big_gaps + 1 ,
1799+ np .nan ,
1800+ axis = 0 ,
1801+ )
17881802
17891803 if self .mode == ViewType .stereo :
17901804 # Now convert from polar to stereo
@@ -1838,13 +1852,15 @@ def tick_values(self, vmin, vmax):
18381852 # Convert back to tth
18391853 return canvas .polar_x_type_to_tth (values )
18401854
1855+
18411856class PolarXAxisMinorTickLocator (AutoMinorLocator ):
18421857 """Subclass the tick locator so we can modify its behavior
18431858
18441859 We will modify any value ranges provided so that the current x-axis type
18451860 provides nice looking ticks.
18461861
1847- For instance, for Q, we want to space minor ticks non-linearly between major ticks
1862+ For instance, for Q, we want to space minor ticks non-linearly between
1863+ major ticks
18481864 """
18491865 def __init__ (self , canvas , * args , ** kwargs ):
18501866 super ().__init__ (* args , ** kwargs )
@@ -1853,14 +1869,15 @@ def __init__(self, canvas, *args, **kwargs):
18531869 def __call__ (self ):
18541870 canvas = self ._hexrdgui_canvas
18551871 if self .axis .get_scale () == 'log' :
1856- logging .warning ('PolarXAxisMinorTickLocator does not work on logarithmic scales' )
1872+ logging .warning (
1873+ 'PolarXAxisMinorTickLocator does not work on logarithmic '
1874+ 'scales'
1875+ )
18571876 return []
18581877
18591878 majorlocs = np .unique (self .axis .get_majorticklocs ())
18601879 if len (majorlocs ) < 2 :
18611880 # Need at least two major ticks to find minor tick locations.
1862- # TODO: Figure out a way to still be able to display minor ticks with less
1863- # than two major ticks visible. For now, just display no ticks at all.
18641881 return []
18651882
18661883 # Convert to our current x type
@@ -1874,7 +1891,10 @@ def __call__(self):
18741891
18751892 if self .ndivs == 'auto' :
18761893 majorstep_mantissa = 10 ** (np .log10 (majorstep ) % 1 )
1877- ndivs = 5 if np .isclose (majorstep_mantissa , [1 , 2.5 , 5 , 10 ]).any () else 4
1894+ if np .isclose (majorstep_mantissa , [1 , 2.5 , 5 , 10 ]).any ():
1895+ ndivs = 5
1896+ else :
1897+ ndivs = 4
18781898 else :
18791899 ndivs = self .ndivs
18801900
0 commit comments