使用Julia中的Plots.jl包,我可以使用各种后端根据两个向量x
和y
k = 100
x = rand(k)
y = rand(k)
scatter(x, y)
我无法找到有关如何根据长度k
向量z
对其进行着色的信息。你是怎么做到的?
答案 0 :(得分:5)
以下方法将比jverzani更好(您不想为每个数据点创建新系列)。 Plots可以使用一些额外的爱来手动定义颜色向量,但是现在渐变得到很好的支持,所以你可以利用它。
using Plots
pyplot(size=(400,200), legend=false) # set backend and set some session defaults
scatter(rand(30),
m = ColorGradient([:red, :green, :blue]), # colors are defined by a gradient
zcolor = repeat( [0,0.5,1], 10) # sample from the gradient, cycling through: 0, 0.5, 1
)
答案 1 :(得分:2)
我原本以为如果你将input {
display: block;
width: 100%;
margin-bottom: 10px;
}
定义为颜色符号的矢量,那么它就可以工作:k
,但它似乎并不适用。但是,一次添加一个,如下例所示:
scatter(x, y, markercolors=k)
答案 2 :(得分:1)
如果向量z中的元素是类别值而不是连续值,则可能需要考虑对绘图调用使用group
参数,如下所示:
using Plots
# visualize x and y colouring points based on category z
scatter(x, y, group=z)