Matplotlib Quiver 绘图匹配键标签颜色和箭头颜色 [英] Matplotlib Quiver plot matching key label color with arrow color
问题描述
使用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)]],角度=[[45],[90]])plt.quiverkey(q,.5,.5,7,r'vector2',labelcolor =(0.3,0.1,.2,1),labelpos='S', 坐标 = '人物')
据说您打算使用 quiver
的 color
参数来设置实际颜色.
>
将matplotlib.pyplot导入为pltq=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)])plt.quiverkey(q,.5,.5,7,r'vector2',labelcolor =(0.3,0.1,.2,1),labelpos='S', 坐标 = '人物')plt.show()
否则, C
参数将被解释为根据默认颜色图映射到颜色的值.由于您只有两个箭头,因此只考虑给定 C
参数的数组中8个数字中的前两个值.但是颜色图归一化使用所有这些值,因此范围在0.1到1.0之间.通话
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)])
因此
等同于
q = plt.quiver([1,2,],[1,1],[5,0],[5,5],[0.6,0.8],norm = plt.Normalize(vmin = 0.1,vmax = 1))
在箭头颜色映射中,第一个箭头颜色的值为0.6,在0.1和1.0之间进行归一化;在该颜色映射中,第二个箭头颜色为0.8.
如果我们添加 plt.colorbar(q,orientation="horizontal")
,这会变得很明显:
Using matplotlib, python3.6. I am trying to create some quiverkeys for a quiver plot but having a hard time getting the label colors to match certain arrows. Below is a simplified version of the code to show the issue. When I use the same color (0.3, 0.1, 0.2, 1.0 ) for a vector at (1,1) and as 'labelcolor' of a quiverkey I see 2 different colors.
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')
Supposedly you meant to be using the color
argument of quiver
to set the actual colors.
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()
Else, the C
argument is interpreted as the values to map to colors according to the default colormap. Since you only have two arrows, only the first two values from the 8 numbers in the array given to the C
argument are taken into account. But the colormap normalization uses all of those values, such that it ranges between 0.1 and 1.0. The call
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 )])
is hence equivalent to
q=plt.quiver([1, 2,], [1, 1], [5,0], [5,5],
[0.6, 0.8], norm=plt.Normalize(vmin=0.1, vmax=1))
resulting in the first arrows color to be the value of 0.6 in the viridis colormap normalized between 0.1 and 1.0, and the second arrow to 0.8 in that colormap.
This becomes apparent if we add plt.colorbar(q, orientation="horizontal")
:
这篇关于Matplotlib Quiver 绘图匹配键标签颜色和箭头颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!