Matplotlib Quiver图将关键标签颜色与箭头颜色匹配

时间:2019-04-26 16:22:26

标签: python-3.x matplotlib

使用matplotlib,python3.6。我正在尝试为颤动图创建一些颤动键,但是很难获取标签颜色以匹配某些箭头。下面是显示问题的简化代码。当我对(1,1)的向量使用相同的颜色(0.3、0.1、0.2、1.0)时,并作为quiverkey的'labelcolor',我看到2种不同的颜色。

q=plt.quiver([1, 2,], [1, 1],
       [[49],[49]],
       [0],
   [[(0.6, 0.8, 0.5, 1.0 )],
    [(0.3, 0.1, 0.2, 1.0 )]],
       angles=[[45],[90]],
       )
plt.quiverkey(q, .5, .5, 7, r'vector2', labelcolor=(0.3, 0.1, .2, 1),
                      labelpos='S', coordinates = 'figure')

enter image description here

1 个答案:

答案 0 :(得分:1)

假设您打算使用color的{​​{1}}参数来设置实际颜色。

quiver

enter image description here

否则,import matplotlib.pyplot as plt q=plt.quiver([1, 2,], [1, 1], [5,0], [5,5], color=[(0.6, 0.8, 0.5, 1.0 ), (0.3, 0.1, 0.2, 1.0 )]) plt.quiverkey(q, .5, .5, 7, r'vector2', labelcolor=(0.3, 0.1, .2, 1), labelpos='S', coordinates = 'figure') plt.show() 参数将被解释为根据默认颜色图映射到颜色的值。由于您只有两个箭头,因此仅考虑数组中分配给C参数的8个数字中的前两个值。但是颜色图归一化使用所有这些值,因此范围在0.1到1.0之间。通话

C
因此

等同于

q=plt.quiver([1, 2,], [1, 1], [5,0], [5,5],
             [(0.6, 0.8, 0.5, 1.0 ), (0.3, 0.1, 0.2, 1.0 )])

在箭头颜色映射中,第一个箭头颜色的值为0.6,在0.1和1.0之间进行归一化;在该颜色映射中,第二个箭头的颜色为0.8。

如果我们添加q=plt.quiver([1, 2,], [1, 1], [5,0], [5,5], [0.6, 0.8], norm=plt.Normalize(vmin=0.1, vmax=1)) ,这将变得显而易见:

enter image description here

相关问题