How to check if colorbar exists on figure

前端 未结 4 1660
遥遥无期
遥遥无期 2020-12-18 03:33

Question: Is there a way to check if a color bar already exists?

I am making many plots with a loop. The issue is that the color bar is drawn every

4条回答
  •  清酒与你
    2020-12-18 04:01

    One approach is:

    1. initially (prior to having any color bar drawn), set a variable

      colorBarPresent = False
      
    2. in the method for drawing the color bar, check to see if it's already drawn. If not, draw it and set the colorBarPresent variable True:

      def drawColorBar():
          if colorBarPresent:
              # leave the function and don't draw the bar again
          else:
              # draw  the color bar
              colorBarPresent = True
      

提交回复
热议问题