@@ -414,6 +414,9 @@ def _plot_panel(ax, title, array, colormap, norm, levels, ticks, contours,
414414 plottitle_font = {'size' : config .get ('plot' ,
415415 'threePanelPlotTitleFontSize' )}
416416
417+ multi_line_ref_title = (
418+ refArray is not None and refTitle is not None and '\n ' in refTitle )
419+
417420 if refArray is None :
418421 subplots = [111 ]
419422 else :
@@ -427,21 +430,43 @@ def _plot_panel(ax, title, array, colormap, norm, levels, ticks, contours,
427430 dictDiff = setup_colormap (config , colorMapSectionName , suffix = 'Difference' )
428431
429432 axes = []
430- ax = plt .subplot (subplots [0 ], projection = projection )
431- _plot_panel (ax , modelTitle , modelArray , ** dictModelRef )
432- axes .append (ax )
433+ if refArray is not None and multi_line_ref_title :
434+ # Use a GridSpec with unequal gaps but equal-sized panels
435+ gs = fig .add_gridspec (
436+ nrows = 5 ,
437+ ncols = 1 ,
438+ height_ratios = [1.0 , 0.18 , 1.0 , 0.08 , 1.0 ])
439+
440+ ax = fig .add_subplot (gs [0 , 0 ], projection = projection )
441+ _plot_panel (ax , modelTitle , modelArray , ** dictModelRef )
442+ axes .append (ax )
433443
434- if refArray is not None :
435- ax = plt .subplot (subplots [1 ], projection = projection )
444+ ax = fig .add_subplot (gs [2 , 0 ], projection = projection )
436445 _plot_panel (ax , refTitle , refArray , ** dictModelRef )
437446 axes .append (ax )
438447
439- ax = plt . subplot ( subplots [ 2 ], projection = projection )
448+ ax = fig . add_subplot ( gs [ 4 , 0 ], projection = projection )
440449 _plot_panel (ax , diffTitle , diffArray , ** dictDiff )
441450 axes .append (ax )
451+ else :
452+ ax = plt .subplot (subplots [0 ], projection = projection )
453+ _plot_panel (ax , modelTitle , modelArray , ** dictModelRef )
454+ axes .append (ax )
455+
456+ if refArray is not None :
457+ ax = plt .subplot (subplots [1 ], projection = projection )
458+ _plot_panel (ax , refTitle , refArray , ** dictModelRef )
459+ axes .append (ax )
460+
461+ ax = plt .subplot (subplots [2 ], projection = projection )
462+ _plot_panel (ax , diffTitle , diffArray , ** dictDiff )
463+ axes .append (ax )
442464
443465 _add_stats (modelArray , refArray , diffArray , Lats , axes )
444466
467+ # Note: in the multi-line reference-title case, uneven spacing is handled
468+ # via GridSpec so all three panels keep identical sizes.
469+
445470 if fileout is not None :
446471 savefig (fileout , config , pad_inches = 0.2 )
447472
@@ -775,12 +800,12 @@ def _add_stats(modelArray, refArray, diffArray, Lats, axes):
775800
776801def _add_stats_text (names , values , ax , loc ):
777802 if loc == 'upper' :
778- text_ax = inset_axes (ax , width = '17 %' , height = '20%' , loc = 'upper right' ,
779- bbox_to_anchor = (0.2 , 0.1 , 1. , 1. ),
803+ text_ax = inset_axes (ax , width = '19 %' , height = '20%' , loc = 'upper right' ,
804+ bbox_to_anchor = (0.22 , 0.1 , 1. , 1. ),
780805 bbox_transform = ax .transAxes , borderpad = 0 )
781806 else :
782- text_ax = inset_axes (ax , width = '17 %' , height = '20%' , loc = 'lower right' ,
783- bbox_to_anchor = (0.2 , 0.03 , 1. , 1. ),
807+ text_ax = inset_axes (ax , width = '19 %' , height = '20%' , loc = 'lower right' ,
808+ bbox_to_anchor = (0.22 , 0.03 , 1. , 1. ),
784809 bbox_transform = ax .transAxes , borderpad = 0 )
785810
786811 text = '\n ' .join (names )
0 commit comments