@@ -627,50 +627,46 @@ def __show2D(self,datacontainers, title=None, slice_list=None, fix_range=False,
627627 num_cols = num_plots
628628
629629 num_rows = num_plots // num_cols + (num_plots % num_cols > 0 )
630- fig , (ax ) = plt .subplots (num_rows , num_cols , figsize = size )
631- axes = ax .flatten ()
630+ fig , axs = plt .subplots (num_rows , num_cols , figsize = size , squeeze = False )
632631
633- #set up plots
634- for i in range (num_rows * num_cols ):
635- axes [i ].set_visible (False )
632+ for axis in axs .flat [num_plots :]:
633+ fig .delaxes (axis )
636634
637- for i , subplot in enumerate (subplots ):
638-
639- axes [i ].set_visible (True )
640- axes [i ].set_title (subplot .title )
635+ for i , (axis , subplot ) in enumerate (zip (axs .flat , subplots )):
636+ axis .set_title (subplot .title )
641637
642638 if subplot .axis_labels is not None :
643- axes [ i ] .set_ylabel (subplot .axis_labels [1 ])
644- axes [ i ] .set_xlabel (subplot .axis_labels [0 ])
639+ axis .set_ylabel (subplot .axis_labels [1 ])
640+ axis .set_xlabel (subplot .axis_labels [0 ])
645641
646642 #set origin
647643 data , data_origin , extent = set_origin (subplot .data , subplot .origin )
648644 if isinstance (cmap , (list , tuple )):
649645 dcmap = cmap [i ]
650646 else :
651647 dcmap = cmap
652- sp = axes [ i ] .imshow (data , cmap = dcmap , origin = data_origin , extent = extent )
648+ sp = axis .imshow (data , cmap = dcmap , origin = data_origin , extent = extent )
653649
654650 im_ratio = subplot .data .shape [0 ]/ subplot .data .shape [1 ]
655651
656652 y_axes2 = False
657653 if isinstance (subplot .data ,(AcquisitionData )):
658- if axes [ i ] .get_ylabel () == 'angle' :
659- locs = axes [ i ] .get_yticks ()
654+ if axis .get_ylabel () == 'angle' :
655+ locs = axis .get_yticks ()
660656 location_new = locs [0 :- 1 ].astype (int )
661657
662658 ang = subplot .data .geometry .config .angles
663659
664660 labels_new = ["{:.2f}" .format (i ) for i in np .take (ang .angle_data , location_new )]
665- axes [ i ] .set_yticks (location_new , labels = labels_new )
661+ axis .set_yticks (location_new , labels = labels_new )
666662
667- axes [ i ] .set_ylabel ('angle / ' + str (ang .angle_unit ))
663+ axis .set_ylabel ('angle / ' + str (ang .angle_unit ))
668664
669- y_axes2 = axes [ i ] .axes .secondary_yaxis ('right' )
665+ y_axes2 = axis .axes .secondary_yaxis ('right' )
670666 y_axes2 .set_ylabel ('angle / index' )
671667
672668 if subplot .data .shape [0 ] < subplot .data .shape [1 ]// 2 :
673- axes [ i ] .set_aspect (1 / im_ratio )
669+ axis .set_aspect (1 / im_ratio )
674670 im_ratio = 1
675671
676672 if y_axes2 :
@@ -680,7 +676,7 @@ def __show2D(self,datacontainers, title=None, slice_list=None, fix_range=False,
680676 scale = 0.0467 * im_ratio
681677 pad = 0.02
682678
683- plt .colorbar (sp , orientation = 'vertical' , ax = axes [ i ], fraction = scale , pad = pad )
679+ plt .colorbar (sp , orientation = 'vertical' , ax = axis , fraction = scale , pad = pad )
684680
685681 if subplot .range is not None :
686682 sp .set_clim (subplot .range [0 ],subplot .range [1 ])
0 commit comments