2017-08-12 59 views
0

有没有方法可以更改散景图例中字形的alpha值?如何更改散景图例中字形的alpha值

以此为例。我将图中的线条的alpha设置为0.1,但图例中的线条字形也反映了此Alpha值。

您可以更改图例中所有其他元素的Alpha(即边框,文本,背景),但不是字形?!

这很令人沮丧,因为这意味着我无法确定哪种颜色与哪个标签相关联(如果Alpha设置为低)。

import numpy as np 
from bokeh.plotting import output_file, figure, show 
x = np.linspace(0, 4*np.pi, 100) 
y = np.sin(x) 
alpha = .1 
output_file("legend_background.html") 
p = figure() 
p.line(x, y, legend="sin(x)", line_alpha=alpha) 
p.line(x, 2*y, legend="2*sin(x)", 
     line_dash=[4, 4], line_color="orange", line_width=2, line_alpha=alpha) 
p.line(x, 3*y, legend="3*sin(x)", line_color="green", line_alpha=alpha) 
p.legend.location = "top_right" 
show(p) 

只要能够做到像p.legend.glyph_alpha = 0.9这样的东西就太好了。

为了澄清:在实际使用情况下,这涉及到,我可以具有向上的100000线(即30000从一个标签,并从另一个70,000),因此,我希望能够以设置线的α在阴谋很低寻找重叠的趋势等

回答

0

我会争辩说,与一个低,你甚至无法看到该行的alpha。但无论如何,你不应该改变图例中的alpha,因为它实际上会在颜色上产生细微的差异。类似的例子:

import numpy as np 
from bokeh.plotting import output_file, figure, show 
x = np.linspace(0, 4*np.pi, 100) 
y = np.sin(x) 

output_file("legend_background.html") 
p = figure() 
p.line(x, y, legend="sin(x)", line_color='black',line_alpha=.2) 
p.line(x, 2*y, legend="2*sin(x)",line_dash=[4, 4], line_color="black",line_width=2, line_alpha=.7) 
p.line(x, 3*y, legend="3*sin(x)", line_color="black", line_alpha=1) 
show(p) 

enter image description here

编辑 我无法找到如何做到这一点的任何文档,但如果你只有2与2种颜色分组,你可以只绘制一个附加与您使用实际标签查看的域之外的标签相同。即这是修复你的传奇的一种粗糙的方式,但它的工作原理。

p.line(x, y, line_color='black',line_alpha=.1) 
p.line(x, 2*y,line_dash=[4, 4], line_color="orange", line_width=2,line_alpha=.1) 
p.line(x, 3*y, line_color="green", line_alpha=.1) 
p.line(x, y+1000, legend="sin(x)", line_color='black',line_alpha=1) 
p.line(x, 2*y+1000, legend="2*sin(x)",line_dash=[4, 4], line_color="orange", 
line_width=2, line_alpha=1) 
p.line(x, 3*y+1000, legend="3*sin(x)", line_color="green", line_alpha=1) 

enter image description here

+0

实际的真实使用情况下,这个问题涉及到我可以有向上的100,000行 - 所以它是一个很大的区别。这个答案没有解决我提出的问题。 –

+0

感谢您的额外信息,我编辑了回复。我觉得密度等值线图将是分析数据的更好方法。 – BenT

+0

原油是好的,如果它的工作。感谢关于密度轮廓的建议 - 我会看看它如何与我的数据一起工作。 –