用颜色z在坐标(x,y)上绘制(x,y,z)三元组 [英] Plot (x,y,z) triplets over coordinates (x,y) with color z
问题描述
我有一个点(x,y,z)的列表,并想将它们可视化为点上(x,y)且点的颜色/强度/厚度为z的平面上的曲线.如何在Matlab中完成?
I've got a list of points (x,y,z) and would like to visualize them as a curve on a plane with points on (x,y) and any of color/intensity/thickness as z. How can this be done in Matlab?
plot(x,y)
的形状正确,但是我需要颜色取决于z
.
plot(x,y)
gets the right shape, but I need the color to depend on z
.
推荐答案
假定您不在乎实际线条的颜色,而是在乎标记. plot
与scatter
结合使用.
Assuming you don't care about the color of the actual line, but the markers. Use plot
in combination with scatter
.
想象以下示例数据:
t = 0:pi/20:2*pi;
x = sin(t);
y = cos(t);
z = t;
plot3(x,y,z);
绘制在2D平面中:
plot(x,y); hold on
scatter(x,y,300,z); hold off
导致:
根据您的评论:如果您有足够的数据并且不需要该行,只需使用scatter
,这正是您所需要的.
From your comment: if you have enough data and you don't need the line, just use scatter
, it's exactly what you need.
另一种可能性是受解决方案.
surface([x;x],[y;y],zeros(2,length(t)),[z;z],'EdgeColor','flat',...
'Marker','o','MarkerSize',10,'MarkerFaceColor','flat');
使颜色依赖于z
非常容易,要更改标记大小,您肯定需要scatter
函数:
Make the color dependent on z
is quite easy, for changing marker sizes you definitely need the scatter
function:
surface([x;x],[y;y],zeros(2,length(t)),[z;z],'EdgeColor','flat'); hold on
MarkerSize = round(z*1000)+1;
scatter(x,y,MarkerSize,z,'.','MarkerFaceColor','auto'); hold off
对于z
取决于,增加透明度有点棘手.您可以使用 此处 找到解决方法patch
功能.
For on z
depending, increasing transparency it's a little tricky. You can find a workaround here, using the patch
function.
这篇关于用颜色z在坐标(x,y)上绘制(x,y,z)三元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!