@@ -494,8 +494,8 @@ def __init__(self, fig,
494494 share_all False [ True | False ]
495495 aspect True [ True | False ]
496496 label_mode "L" [ "L" | "1" | "all" ]
497- cbar_mode None [ "each" | "single" ]
498- cbar_location "right" [ "right" | "top" ]
497+ cbar_mode None [ "each" | "single" | "edge" ]
498+ cbar_location "right" [ "left" | " right" | "bottom " | "top" ]
499499 cbar_pad None
500500 cbar_size "5%"
501501 cbar_set_cax True [ True | False ]
@@ -631,42 +631,78 @@ def __init__(self, fig,
631631 def _update_locators (self ):
632632
633633 h = []
634+ v = []
634635
635636 h_ax_pos = []
636637 h_cb_pos = []
637- for ax in self ._column_refax :
638- if h : h .append (self ._horiz_pad_size ) #Size.Fixed(self._axes_pad))
638+ if self ._colorbar_mode == "single" and self ._colorbar_location in ('left' , 'bottom' ):
639+ if self ._colorbar_location == "left" :
640+ #sz = Size.Fraction(Size.AxesX(self.axes_llc), self._nrows)
641+ sz = Size .Fraction (self ._nrows , Size .AxesX (self .axes_llc ))
642+ h .append (Size .from_any (self ._colorbar_size , sz ))
643+ h .append (Size .from_any (self ._colorbar_pad , sz ))
644+ locator = self ._divider .new_locator (nx = 0 , ny = 0 , ny1 = - 1 )
645+ elif self ._colorbar_location == "bottom" :
646+ #sz = Size.Fraction(Size.AxesY(self.axes_llc), self._ncols)
647+ sz = Size .Fraction (self ._ncols , Size .AxesY (self .axes_llc ))
648+ v .append (Size .from_any (self ._colorbar_size , sz ))
649+ v .append (Size .from_any (self ._colorbar_pad , sz ))
650+ locator = self ._divider .new_locator (nx = 0 , nx1 = - 1 , ny = 0 )
651+ for i in range (self .ngrids ):
652+ self .cbar_axes [i ].set_visible (False )
653+ self .cbar_axes [0 ].set_axes_locator (locator )
654+ self .cbar_axes [0 ].set_visible (True )
639655
640- h_ax_pos .append (len (h ))
656+ for col ,ax in enumerate (self ._column_refax ):
657+ if h : h .append (self ._horiz_pad_size ) #Size.Fixed(self._axes_pad))
641658
642659 if ax :
643660 sz = Size .AxesX (ax )
644661 else :
645662 sz = Size .AxesX (self .axes_llc )
663+
664+ if (self ._colorbar_mode == "each" or
665+ (self ._colorbar_mode == 'edge' and
666+ col == 0 )) and self ._colorbar_location == "left" :
667+ h_cb_pos .append (len (h ))
668+ h .append (Size .from_any (self ._colorbar_size , sz ))
669+ h .append (Size .from_any (self ._colorbar_pad , sz ))
670+
671+ h_ax_pos .append (len (h ))
672+
646673 h .append (sz )
647674
648- if self ._colorbar_mode == "each" and self ._colorbar_location == "right" :
675+ if (self ._colorbar_mode == "each" or
676+ (self ._colorbar_mode == 'edge' and
677+ col == self ._ncols - 1 )) and self ._colorbar_location == "right" :
649678 h .append (Size .from_any (self ._colorbar_pad , sz ))
650679 h_cb_pos .append (len (h ))
651680 h .append (Size .from_any (self ._colorbar_size , sz ))
652681
653682
654- v = []
655-
656683 v_ax_pos = []
657684 v_cb_pos = []
658- for ax in self ._row_refax [::- 1 ]:
685+ for row , ax in enumerate ( self ._row_refax [::- 1 ]) :
659686 if v : v .append (self ._horiz_pad_size ) #Size.Fixed(self._axes_pad))
660687
661- v_ax_pos .append (len (v ))
662688 if ax :
663689 sz = Size .AxesY (ax )
664690 else :
665691 sz = Size .AxesY (self .axes_llc )
666- v .append (sz )
667692
693+ if (self ._colorbar_mode == "each" or
694+ (self ._colorbar_mode == 'edge' and
695+ row == 0 )) and self ._colorbar_location == "bottom" :
696+ v_cb_pos .append (len (v ))
697+ v .append (Size .from_any (self ._colorbar_size , sz ))
698+ v .append (Size .from_any (self ._colorbar_pad , sz ))
668699
669- if self ._colorbar_mode == "each" and self ._colorbar_location == "top" :
700+ v_ax_pos .append (len (v ))
701+ v .append (sz )
702+
703+ if (self ._colorbar_mode == "each" or
704+ (self ._colorbar_mode == 'edge' and
705+ row == self ._nrows - 1 )) and self ._colorbar_location == "top" :
670706 v .append (Size .from_any (self ._colorbar_pad , sz ))
671707 v_cb_pos .append (len (v ))
672708 v .append (Size .from_any (self ._colorbar_size , sz ))
@@ -680,13 +716,24 @@ def _update_locators(self):
680716 self .axes_all [i ].set_axes_locator (locator )
681717
682718 if self ._colorbar_mode == "each" :
683- if self ._colorbar_location == "right" :
719+ if self ._colorbar_location in ( "right" , "left" ) :
684720 locator = self ._divider .new_locator (nx = h_cb_pos [col ],
685721 ny = v_ax_pos [self ._nrows - 1 - row ])
686- elif self ._colorbar_location == "top" :
722+ elif self ._colorbar_location in ( "top" , "bottom" ) :
687723 locator = self ._divider .new_locator (nx = h_ax_pos [col ],
688724 ny = v_cb_pos [self ._nrows - 1 - row ])
689725 self .cbar_axes [i ].set_axes_locator (locator )
726+ elif self ._colorbar_mode == 'edge' :
727+ if ((self ._colorbar_location == 'left' and col == 0 ) or
728+ (self ._colorbar_location == 'right' and col == self ._ncols - 1 )):
729+ locator = self ._divider .new_locator (nx = h_cb_pos [0 ],
730+ ny = v_ax_pos [self ._nrows - 1 - row ])
731+ self .cbar_axes [row ].set_axes_locator (locator )
732+ elif ((self ._colorbar_location == 'bottom' and row == self ._nrows - 1 ) or
733+ (self ._colorbar_location == 'top' and row == 0 )):
734+ locator = self ._divider .new_locator (nx = h_ax_pos [col ],
735+ ny = v_cb_pos [0 ])
736+ self .cbar_axes [col ].set_axes_locator (locator )
690737
691738
692739 if self ._colorbar_mode == "single" :
@@ -702,13 +749,23 @@ def _update_locators(self):
702749 v .append (Size .from_any (self ._colorbar_pad , sz ))
703750 v .append (Size .from_any (self ._colorbar_size , sz ))
704751 locator = self ._divider .new_locator (nx = 0 , nx1 = - 1 , ny = - 2 )
705- for i in range (self .ngrids ):
706- self .cbar_axes [i ].set_visible (False )
707- self .cbar_axes [0 ].set_axes_locator (locator )
708- self .cbar_axes [0 ].set_visible (True )
752+ if self ._colorbar_location in ("right" , "top" ):
753+ for i in range (self .ngrids ):
754+ self .cbar_axes [i ].set_visible (False )
755+ self .cbar_axes [0 ].set_axes_locator (locator )
756+ self .cbar_axes [0 ].set_visible (True )
709757 elif self ._colorbar_mode == "each" :
710758 for i in range (self .ngrids ):
711759 self .cbar_axes [i ].set_visible (True )
760+ elif self ._colorbar_mode == "edge" :
761+ if self ._colorbar_location in ('right' , 'left' ):
762+ count = self ._nrows
763+ else :
764+ count = self ._ncols
765+ for i in range (count ):
766+ self .cbar_axes [i ].set_visible (True )
767+ for j in range (i + 1 , self .ngrids ):
768+ self .cbar_axes [j ].set_visible (False )
712769 else :
713770 for i in range (self .ngrids ):
714771 self .cbar_axes [i ].set_visible (False )
0 commit comments