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!



