Matlab plot3 line color setting

83 次查看(过去 30 天)
Mohsin Khan
Mohsin Khan 2022-2-14
I want to plot a three-dimensional line chart using the plot3 function in matlab. The following code works to plot the lines with specified colour names 'r','g','k', etc. However,Iit gives an error when I replace the first colour by 'myGreen' using the RGB triplet: 'Error using plot3 Vectors must be the same length.'
How can I resolve this issue?
[xx,zz]=meshgrid(1:230,1:4);
x1=(xx(1,:));
x2=(xx(2,:));
x3=(xx(3,:));
x4=(xx(4,:));
z1=(zz(1,:));
z2=(zz(2,:));
z3=(zz(3,:));
z4=(zz(4,:));
yy=rand(230,4);
y1=(yy(:,1));
y2=(yy(:,2));
y3=(yy(:,3));
y4=(yy(:,4));
% custom colour
myGreen=[0 0.5 0];
index={'data1','data2','data3','data4'}
figure
% It works and produces the attached figure
plot3(x1',z1',y1','r',x2',z2',y2','m', x3',z3',y3','b',x4',z4',y4','k')
% It doesn't work
plot3(x1',z1',y1','Color',myGreen,x2',z2',y2','m', x3',z3',y3','b',x4',z4',y4','k')
set(gca,'YTick',1:4,'YTickLabel',index)
grid on
xlabel('xlabel','FontSize',10);
zlabel('zlabel','FontSize',10)
axis tight

回答(1 个)

Yongjian Feng
Yongjian Feng 2022-2-14
Separate them:
plot3(x1',z1',y1','Color', myGreen);
hold on
plot3(x2',z2',y2', 'm', x3',z3',y3','b', x4',z4',y4','k');

类别

Help CenterFile Exchange 中查找有关 Graphics Objects 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by