How can a single line plot have two colors?
Mostrar comentarios más antiguos
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')
Respuesta aceptada
Más respuestas (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 comentarios
Tunde Adubi
el 24 de Jul. de 2023
Editada: Tunde Adubi
el 24 de Jul. de 2023
Sam Chak
el 24 de Jul. de 2023
@Tunde Adubi, Can you check whether the variables in your script are overshadowed by the variables having the same name in your workspace?
Categorías
Más información sobre Two y-axis en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



