如何使用Plots.jl根据z中的值对(x,y)散点图进行着色? [英] How do you color (x,y) scatter plots according to values in z using Plots.jl?

查看:108
本文介绍了如何使用Plots.jl根据z中的值对(x,y)散点图进行着色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Julia中的Plots.jl包,我可以使用各种后端基于两个向量xy

Using the Plots.jl package in Julia, I am able to use various backends to make a scatter plot based on two vectors x and y

k = 100
x = rand(k)
y = rand(k)
scatter(x, y)

我无法找到有关如何根据某些长度k矢量z对其进行着色的信息.你怎么做到的?

I am unable to find information about how to color them according to some length k vector z. How do you do that?

推荐答案

以下方法将比jverzani的方法好得多(您不想为每个数据点创建一个新的序列).绘图可以使用一些额外的技巧来手动定义颜色矢量,但是现在已经很好地支持了渐变,因此您可以利用它.

The following method will be much better than jverzani's (you don't want to create a new series for every data point). Plots could use some additional love for manually defining color vectors, but right now gradients are pretty well supported, so you can take advantage of that.

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
       )

这篇关于如何使用Plots.jl根据z中的值对(x,y)散点图进行着色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆