我试图获得一个带有半透明紫色填充区域的 plotly 图。我可以很好地找到 rgb 名称并让它在一个简单的图中工作。但似乎 plotly 并没有以 rgb 的通常方式读取?
plot(rnorm(10),col="#A020F066",pch=15,cex=13)
# plots squares that are transparent purple (expected)
p=plot_ly(x=c(1,2,3,4),y=c(1,2,5,10),type="scatter",line=list(color="red"))
p=add_trace(p,x=c(1,2,3,4),y=c(11,12,15,20),type="scatter",
fillcolor="#A020F066",fill="tonexty",
line=list(width=10),marker=list(size=10))
p
# plots area that is transparent mint green (What? I expected purple)
最佳答案
根据 plotly 网站,可以在此处找到 rgb/hex 的完整列表( http://reeddesign.co.uk/test/namedcolors.html )。因此,对于您的示例,您需要使用 fillcolor="#8a2be2"
.或者,您也可以使用类似这样的东西 fillcolor="rgba(147,112,219,0.1)
最后一位数字是 alpha(不透明度)
关于plotly和R中的rgb透明颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35213766/