필터 지우기
필터 지우기

Using different line style, colour, and legend

조회 수: 30 (최근 30일)
Ke Yeun Yong
Ke Yeun Yong 2023년 10월 1일
댓글: Ke Yeun Yong 2023년 10월 1일
Hi, I have two lines in one graph, I am trying to set different line style, colour and legend of each line.
The following are the code I have so far.
Please give guidance. Very much appreciated.
X = Altitude;
Y = ROC_22K;
Z = ROC_26K;
plot(X([1:42]),Y([1:42]),X([1:42]),Z([1:42]),'Linestyle', '-', 'linewidth', 1.0);
xlabel('Altitude (m)','FontSize',14, 'fontweight', 'bold', 'color', '[0 0 1]')
ylabel('ROC (m/s)','FontSize',14, 'fontweight', 'bold', 'color', '[0 0 1]')
title('Rate of Climb Vs Altitude','FontSize',16, 'fontweight', 'bold', 'color', '#000000')
legend('Rate of Climb','Location','Bestoutside')
grid on
grid minor

채택된 답변

Image Analyst
Image Analyst 2023년 10월 1일
Looks like you know how to use MATLAB. About all I might offer is to use the 'Color' option in plot to specify specific colors. Or you can look at colororder to set up a sequence of default colors to use if you don't use the color option.
If you want different linestyles, I'd plot them separately:
% Plot Y vs. X with one linestyle.
plot(X([1:42]),Y([1:42]), 'Color', 'r', 'Linestyle', '-.', 'linewidth', 1.0); % first linestyle
hold on; % Don't blow away prior plot.
% Plot Z vs. X with a different color and linestyle.
plot(X([1:42]),Z([1:42]), 'Color', 'b', 'Linestyle', '--', 'linewidth', 2.0); % Different linestyle
help colororder
COLORORDER View and set current color order COLORORDER(colors) sets the color order for the current figure. If you set the color order for the figure, then axes in the figure will use the same color order. Specify the color order as a three-column matrix of RGB triplets, the keyword 'default', a cell-array of character vectors, or a string array. COLORORDER(name) sets the color order for the current figure using the predefined set of colors specified by name. Valid names are: gem, gem12, glow, glow12, dye, earth, meadow, reef, sail. COLORORDER(target, ...) sets the color order for the figure or axes specified by target, instead of for the current figure. When target is a figure, COLORORDER sets the DefaultAxesColorOrder on the figure. When target is an axes, COLORORDER sets the ColorOrder property of the axes. colors = COLORORDER returns the color order of the current figure as a three-column matrix of RGB triplets. colors = COLORORDER(target) returns the color order for the figure or axes specified by target. When target is a figure, COLORORDER returns the DefaultAxesColorOrder on the figure. When target is an axes, COLORORDER returns the value of the ColorOrder property of the axes. See also COLORMAP Documentation for colororder doc colororder
  댓글 수: 1
Ke Yeun Yong
Ke Yeun Yong 2023년 10월 1일
It works perfectly, thank you very much :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by