Matlab plot3 line color setting
79 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Yongjian Feng
el 14 de Feb. de 2022
Separate them:
plot3(x1',z1',y1','Color', myGreen);
hold on
plot3(x2',z2',y2', 'm', x3',z3',y3','b', x4',z4',y4','k');
0 comentarios
Ver también
Categorías
Más información sobre Graphics Objects en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!