Matplotlib: How to adjust linewidth in colorbar for contour plot?

前端 未结 2 1762
深忆病人
深忆病人 2021-01-12 14:42

Here\'s a minimal example to generate a plot which illustrates my question:

import matplotlib.pylab as plt
import matplotlib.mpl as mpl
import numpy as np
         


        
2条回答
  •  无人及你
    2021-01-12 15:16

    You just need to find out how to access those lines, let try:

    >>> CB.ax.get_children()
    [, , , , , , , , , , ]
    

    Alright, take a guess, I bet the 5th item is a list of the divider lines. We are looking for some .line objects and there are two. The first one (3rd item) actually is the edge of the entire color bar (if I remember correctly). So I will go for the next .line object.

    Now let's try to modified it in a few ways:

    >>> len(lines1[4].get_linewidths())
    11 #how many item are there? 11 lines
    >>> lines1[4].set_color(['r']*11) #set them all to red, in this example we actually want to have the color stay the same, this is just for a demonstration. 
    >>> lines1[4].set_linewidths([2]*11) #set them all to have linewidth of 2.
    

    the resultenter image description here

提交回复
热议问题