フィルターのクリア

With a ribbon plot, how to make the ribbons go along each matrix row instead of each column?

68 ビュー (過去 30 日間)
Jeff Owen
Jeff Owen 2024 年 7 月 18 日 17:59
コメント済み: dpb 2024 年 7 月 20 日 22:14
In the ribbon command, the ribbons run along each column of the matrix. The Y vector must be of length = to the number of rows in the matrix. How do I get the ribbons to run along each row of the matrix? I tried many combinations of flipud, fliplr, transpose, etc., and either the axis is going in the wrong direction, or the labels are wrong.
Z=[0,1,2,2; 1,2,3,3; 2,3,4,4; 3,4,5,5]
Y=[0;1;2;3]
ribbon(Y,Z,0.1);
Here the ribbons run in the y direction, but I want them to run in the x direction. Nothing else, e.g., the axis numbering, should change.
  4 件のコメント
dpb
dpb 2024 年 7 月 19 日 18:15
編集済み: dpb 2024 年 7 月 19 日 18:16
"...With the type of figure I'm generating, I would be happy with just lines in a 3D plot"
It can be done with plot3 if your Q? hadn't specifically asked about ribbon
t = 0:pi/500:pi;
X(:,1) = sin(t).*cos(10*t);
X(:,2) = sin(t).*cos(12*t);
X(:,3) = sin(t).*cos(20*t);
Y(:,1) = sin(t).*sin(10*t);
Y(:,2) = sin(t).*sin(12*t);
Y(:,3) = sin(t).*sin(20*t);
Z = cos(t);
plot3(X,Y,Z,'color','k')
Using the example of multiple lines from the doc

サインインしてコメントする。

採用された回答

dpb
dpb 2024 年 7 月 19 日 18:24
編集済み: dpb 2024 年 7 月 19 日 19:34
It can be done with plot3 excepting the Q? asked specifically how to do a ribbon.
X=[1:4];
Y=[0:3];
Z=[0,1,2,2; 1,2,3,3; 2,3,4,4; 3,4,5,5].';
plot3(X,Y,Z,'k-')
grid on
xlabel('X'), ylabel('Y')
It would be interesting to see a real dataset...
  2 件のコメント
Jeff Owen
Jeff Owen 2024 年 7 月 20 日 20:06
An even simpler answer. I forgot all about plot3. I was following a rabbit hole with ribbon. Nevertheless, Voss came up with a very simple way to do it. Wish I could accept both answers. You guys rock.
dpb
dpb 2024 年 7 月 20 日 22:14
Indeed, his is a neat trick...but for your expressed end purpose, plot3 is probably the better tool based on your sample plots above, and not the toy dataset for the Q?

サインインしてコメントする。

その他の回答 (2 件)

Voss
Voss 2024 年 7 月 18 日 21:09
編集済み: Voss 2024 年 7 月 18 日 21:10
If you have some leeway on the x- and y-axis tick locations, you can use ribbon with the tranpose of Z and just alter the axis labels and orientation:
Z=[0,1,2,2; 1,2,3,3; 2,3,4,4; 3,4,5,5];
Y = (0:size(Z,2)-1).';
figure
ribbon(Y,Z.',0.1);
xlabel('y')
ylabel('x')
set(gca(),'XDir','reverse')
view([52.5,30])
  4 件のコメント
dpb
dpb 2024 年 7 月 19 日 14:20
Agreed that it is clever with existing ribbon function -- I started down that path but beat me here (although this response wasn't yet up). The y.' is obvious; I wasn't sure @Jeff Owen would think relabeling the axes was kosher or not...
Still, it seems a weakness in the supplied function that it doesn't have the ability to specify which axes orientation against which to draw the ribbons.
Voss
Voss 2024 年 7 月 19 日 14:35
"it seems a weakness in the supplied function that it doesn't have the ability to specify which axes orientation against which to draw the ribbons"
I agree.

サインインしてコメントする。


Voss
Voss 2024 年 7 月 18 日 19:34
Z=[0,1,2,2; 1,2,3,3; 2,3,4,4; 3,4,5,5];
[m,n] = size(Z);
Y = (0:m-1).';
X = (0:n-1).';
Original ribbon plot, for reference:
figure
ribbon(Y,Z,0.1);
xlabel('x')
ylabel('y')
Create surface objects (what ribbon creates), but with the desired properties:
figure
w = 0.1;
for ii = 1:m
surface([X+1,X+1],(ii-1)*ones(n,1)+w/2*[-1 1],Z([ii ii],:).',ii*ones(n,2));
end
view(3)
grid on
xlabel('x')
ylabel('y')
  2 件のコメント
Jeff Owen
Jeff Owen 2024 年 7 月 18 日 21:05
Thank you so much. It absolutely meets my needs. I was going crazy trying to imagine matrix flips, rotations, and transposes in order to do it with "ribbon." You folks have come to the rescue again! :-)
Voss
Voss 2024 年 7 月 18 日 21:10
編集済み: Voss 2024 年 7 月 18 日 21:31
You're welcome! Any questions, let me know.
Also, see my other answer, which uses ribbon and may be acceptable.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by