how to generate the graph with different colors for the following code.

1 visualización (últimos 30 días)
[hAX,hLine1,hLine2] = plotyy(x, [y1; y5], x, [y2; y6], @(X,Y)semilogy(X,Y,'k'), @(X,Y)plot(X,Y,'k');
set(hLine1(1),'LineStyle','-','Marker','o');
set(hLine1(2),'LineStyle','-','Marker','*');
set(hLine2(1),'LineStyle','--','Marker','o');
set(hLine2(2),'LineStyle','--','Marker','*');
Here, I want each line to be represented in different colors instead of black colour. could anyone please help me on this.

Respuesta aceptada

Image Analyst
Image Analyst el 11 de Jul. de 2021
Is there a 'Color' option you could use. For example
colorList = jet(numberOfLines) % eg jet(6);
set(hLine2(1),'LineStyle','--','Marker','o', 'Color', colorList(1, :));
% or
set(hLine2(1),'LineStyle','--','Marker','o', 'Color', 'r'); % Use red
  4 comentarios
jaah navi
jaah navi el 11 de Jul. de 2021
I am getting error stating undefined function or variable 'numberOfLines'.
However I managed to get the graph using the following lines.
[hAX,hLine1,hLine2] = plotyy(x, [y1; y5], x, [y2; y6], @(X,Y)semilogy(X,Y), @(X,Y)plot(X,Y));
set(hLine2(1),'LineStyle','--','Marker','o', 'Color', 'r')
Thanks for your solution.
Image Analyst
Image Analyst el 11 de Jul. de 2021
Well how many lines are you plotting? Two, right? So
numberOfLines = 2;
If you want more specific advice that you don't need to adapt, please attach x, y1, y2, y5, and y6 (all your data)
save('answers.mat', 'x', 'y1', 'y2', 'y5', 'y6');
then use the paperclip icon to attach it here.
Also, do you have any particular colors in mind? You can also make a list of line styles and marker shapes and do basically the same thing. But for only 2 curves, it's probably best not to generalize and just hard code in the color you want with the 'color' option.
See attached demo.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by