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!



