Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从matplotlib中已打印的顺序颜色栏获取线段的颜色_Python_Python 3.x_Matplotlib_Colorbar_Colormap - Fatal编程技术网

Python 从matplotlib中已打印的顺序颜色栏获取线段的颜色

Python 从matplotlib中已打印的顺序颜色栏获取线段的颜色,python,python-3.x,matplotlib,colorbar,colormap,Python,Python 3.x,Matplotlib,Colorbar,Colormap,我需要在matplotlib中已绘制的色条的基础上,使用branca创建一个新的色条 我拥有的对象属于以下类型: <matplotlib.colorbar.Colorbar object at 0x7f089252e790> 在控制台中可以找到某些属性(VS代码集成): 打印(提取的颜色)提供所使用的颜色(我认为): 当最终基于上述解决方法通过branca创建颜色栏时,似乎描述了正确的颜色 尽管如此,我相信必须能够直接从cbar对象检索它们,而不必自己重新生成它们。 我想我只是没有

我需要在
matplotlib
中已绘制的色条的基础上,使用
branca
创建一个新的色条

我拥有的对象属于以下类型:

<matplotlib.colorbar.Colorbar object at 0x7f089252e790>
在控制台中可以找到某些属性(VS代码集成):

打印(提取的颜色)
提供所使用的颜色(我认为):

当最终基于上述解决方法通过branca创建颜色栏时,似乎描述了正确的颜色

尽管如此,我相信必须能够直接从cbar对象检索它们,而不必自己重新生成它们。 我想我只是没有找到
matplotlib.colorbar.colorbar对象
的正确子属性

cbar = plt.colorbar(filled_contours, extend=extend, cax=cax)
In: cbar.values
Out: array([0.00099944, 0.00205833, 0.00311722, 0.00417611, 0.005235  ,
       0.00629389, 0.00735278, 0.00841167, 0.00947056])

In: cbar._y
Out: array([0.        , 0.11111111, 0.22222222, 0.33333333, 0.44444444,
       0.55555556, 0.66666667, 0.77777778, 0.88888889, 1.        ])

In: cbar.cmap.name
Out: 'Reds'

In: cbar.cmap
Out: <matplotlib.colors.LinearSegmentedColormap object at 0x7f08b1d91910>
import matplotlib.pyplot as plt
extracted_cmap = plt.cm.get_cmap(cbar.cmap.name)
extracted_colors = [extracted_cmap(v) for v in cbar._y]
[(1.0, 0.9607843137254902, 0.9411764705882353, 1.0), (0.996555171088043, 0.8884429065743944, 0.8378316032295271, 1.0), (0.9901422529796232, 0.7686120722798924, 0.6780930411380238, 1.0), (0.9882352941176471, 0.6261437908496732, 0.5084967320261438, 1.0), (0.9860976547481738, 0.48704344482891193, 0.3615532487504806, 1.0), (0.9629065743944636, 0.331841599384852, 0.23667820069204154, 1.0), (0.8901960784313725, 0.18562091503267975, 0.15294117647058825, 1.0), (0.7598462129950019, 0.0855363321799308, 0.10609765474817377, 1.0), (0.6175009611687813, 0.05167243367935409, 0.07853902345251824, 1.0), (0.403921568627451, 0.0, 0.05098039215686274, 1.0)]