imagesc, HeatMap or something else with non-rectangular cells
6 次查看(过去 30 天)
显示 更早的评论
Is it possible in the function imagesc or HeatMap to create a color-figure without rectangular cells, but with cells with customized shape (in this case triangular)? Or is there another function which can do this?
Imagine a car driving with varying speed, but its speed is constant during a time step of 5 seconds, thus between 0 and 5 seconds it has some constant speed, between 5 and 10 it has another constant speed, and so on. Its location x1(t) with t in [a,a+5] can be determined from x1(t) = x1(a)+ t*v1(a). Now, there also is a second car (always behind the first one) with location x2(t): x2(t) = x2(a)+t*v2(a). Again, the second car has constant speed in a time interval of 5 seconds. For both cars we have a trajectory in the (t,x)-plane. Sometimes the second car gets closer to the first car and sometimes it gets further away. Hence, the difference x1(t) - x2(t) is not constant (it is a linear function).
Now, I want to assign a color to x1(t) - x2(t). The bigger x1(t) - x2(t), the darker the color should be (for example). So considering the (t,x)-plane it contains two trajectories (x1, x2) and between those trajectories there should be colors indicating the differences x1(t) - x2(t).
Is there a function in MATLAB which can do this? I was thinking about imagesc or heatmap, but they only work with colors in rectangular cells as far as I know.
Thanks in advance!
0 个评论
采纳的回答
Image Analyst
2016-2-1
This seems like a 1-D situation -- x vs. t -- not a 2D situation. How about if you plot x1 and x2 vs. t, and have something, such as the area between the curves shaded with patch() or fill() according to the difference between the curves (like according to the area difference between two times)?
4 个评论
Image Analyst
2016-2-2
Just type "hot" or "hot(256)" in the command line to see a listing of all the RGB colors. You can assign it to a variable if you want.
rgbValuesOfHot = hot(256);
更多回答(1 个)
Mike Garrity
2016-2-1
You can do heatmap like things with triangular meshes, but there is a bit of a learning curve. You're going to want to learn about Triangulation.
Here's a simple example. I'm using delaunayTriangulation because it will generate the triangles for me, but you might want to define your own ConnectivityList.
x = 2*randn(100,1);
y = 2*randn(100,1);
dt = delaunayTriangulation(x,y);
Now I can use the trisurf function to draw a color at each vertex and interpolate across the interior of the triangles.
c = cos(x).*cos(y);
z = zeros(100,1);
trisurf(dt.ConnectivityList,x,y,z,c,'FaceColor','interp')
view(2)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/172611/image.png)
I could also have one color for each triangle.
c = dt.circumcenter;
c = cos(c(:,1)) .* cos(c(:,2));
z = zeros(100,1);
trisurf(dt.ConnectivityList,x,y,z,c,'FaceColor','flat')
view(2)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/172613/image.png)
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!