How can a single line plot have two colors?
이전 댓글 표시
using x and y variables to make a single graph or line plot, how can the plot have two colors or more than one color?
This plot comes out black. How can the interval in the plot attached be red?
figure('position',[100 100 900 550])
hold on
plot(range,s_attenuation,'black', 'LineWidth', 1.5)
ylabel('Specific Attenuation (dB/km)')
xlabel('Range (km)')
title('Line plot')
채택된 답변
추가 답변 (1개)
Hi @Tunde Adubi
If you have the data, and you can find exactly where the two intervals are from scrutizing the data, then you can make the first plot, picking the color hex you like, then retain current plot using 'hold on' when adding another plot. See example below.
You can also use findchangepts() command to find abrupt changes in the signal, if the data has too many points for you to manually scrutize.
% data
x = linspace(0, 1, 1001);
y1 = sin(2*pi*x(1:500));
y2 = sin(2*pi*x(501:end));
% plots
plot(x(1:500), y1, 'linewidth', 2, 'color', '#63c3de'), hold on
plot(x(501:end), y2, 'linewidth', 2, 'color', '#efb255'), hold off
xline(0.5, '--')
% labels
xlabel('x'), ylabel('y')
ylim([-1.5 1.5])
grid on
댓글 수: 2
Tunde Adubi
2023년 7월 24일
편집: Tunde Adubi
2023년 7월 24일
Sam Chak
2023년 7월 24일
@Tunde Adubi, Can you check whether the variables in your script are overshadowed by the variables having the same name in your workspace?
카테고리
도움말 센터 및 File Exchange에서 Two y-axis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



