plotting a series of lines with specified colours

1 vue (au cours des 30 derniers jours)
P_L
P_L le 1 Avr 2019
Commenté : P_L le 1 Avr 2019
Hi,
I am trying to plot a series of lines on a single plot in Matlab2018. I have specified the colours correctly and checked that my data variabes are correct. For some reason I cannot get matlab to plot my data using only the colours I have specified. I have 5 colours - blue, light blue, green, yellow and red (blue = fast velocity and red = slow velocity) and I have two sets of data to be plotted for each colour. You will see in the legend for the image I am producing, that there are other colours being used e.g. purple and that green, for example, hasn't been plotted twice. I do not know how to correct for this and ensure that the plot follows the order I have specified in my code (please see below)
Many Thanks
P
Screenshot 2019-04-01 at 12.34.32.png
clf
clc
clear all
close all
% DATA
Depth= [0 2 4 6 8 12 16 20 24 28 30 32 36 40];
% P-waves
vp_upt= [3.27 5.75 5.85 5.9 5.91 6.15 6.5 6.84 6.84 6.84 6.84 7.34 7.89 7.89];
vp_pve_5= [3.4335 6.0375 6.1425 6.195 6.2055 6.4575 6.825 7.182 7.182 7.182 7.182 7.707 8.2845 8.2845];
vp_pve_25=[3.35175 5.89375 5.99625 6.0475 6.05775 6.30375 6.6625 7.011 7.011 7.011 7.011 7.5235 8.08725 8.08725];
vp_nve_5=[3.1065 5.4625 5.5575 5.605 5.6145 5.8425 6.175 6.498 6.498 6.498 6.498 6.973 7.4955 7.4955];
vp_nve_25=[3.18825 5.60625 5.70375 5.7525 5.76225 5.99625 6.3375 6.669 6.669 6.669 6.669 7.1565 7.69275 7.69275];
% S-waves
vs_upt= [1.91 3.36 3.42 3.44 3.45 3.59 3.79 3.99 3.99 3.99 3.99 4.28 4.61 4.61];
vs_pve_5= [2.0055 3.528 3.591 3.612 3.6225 3.7695 3.9795 4.1895 4.1895 4.1895 4.1895 4.494 4.8405 4.8405];
vs_pve_25=[1.95775 3.444 3.5055 3.526 3.53625 3.67975 3.88475 4.08975 4.08975 4.08975 4.08975 4.387 4.72525 4.72525];
vs_nve_25=[1.86225 3.276 3.3345 3.354 3.36375 3.50025 3.69525 3.89025 3.89025 3.89025 3.89025 4.173 4.49475 4.49475];
vs_nve_5=[1.8145 3.192 3.249 3.268 3.2775 3.4105 3.6005 3.7905 3.7905 3.7905 3.7905 4.066 4.3795 4.3795];
% plot data
% colours
c_blue=[0 102 204]/255;
c_light_b=[0 255 255]/255;
c_green=[88 171 45]/255;
c_yellow=[255 220 15]/255;
c_red=[207 46 49]/255;
plot(vs_pve_5,-Depth,'MarkerEdgeColor',c_blue,'MarkerFaceColor',c_blue,'Linewidth',2);
hold on ;
plot(vs_pve_25,-Depth,'MarkerEdgeColor',c_light_b,'MarkerFaceColor',c_light_b,'Linewidth',2);
hold on ;
plot(vs_upt, -Depth,'MarkerEdgeColor',c_green,'MarkerFaceColor',c_green,'Linewidth',2);
hold on;
plot(vs_nve_25,-Depth,'MarkerEdgeColor',c_yellow,'MarkerFaceColor',c_yellow,'Linewidth',2);
hold on ;
plot(vs_nve_5,-Depth,'MarkerEdgeColor',c_red,'MarkerFaceColor',c_red,'Linewidth',2);
hold on ;
% add p -wave models
plot(vp_pve_5,-Depth,'MarkerEdgeColor',c_blue,'MarkerFaceColor',c_blue,'Linewidth',2);
hold on ;
plot(vp_pve_25,-Depth,'MarkerEdgeColor',c_light_b,'MarkerFaceColor',c_light_b,'Linewidth',2);
hold on ;
plot(vp_upt,-Depth,'MarkerEdgeColor',c_green,'MarkerFaceColor',c_green,'Linewidth',2);
hold on;
plot(vp_nve_25,-Depth,'MarkerEdgeColor',c_yellow,'MarkerFaceColor',c_yellow,'Linewidth',2);
hold on;
plot(vp_nve_5,-Depth,'MarkerEdgeColor',c_red,'MarkerFaceColor',c_red,'Linewidth',2);
% axis
%set(gca, 'FontName','Helvetica','FontSize', 14);
title(' 1-D Velocity Models')
xlabel('Velocity (km/s)')
ylabel('Depth (km)')
legend ('S-wave velocity model increased by 5%', 'S-wave velocity model increased by 2.5%','Unperturbed S-wave velocity model','S-wave model decreased by 2.5%','S-wave velocity model decreased by 5%', 'P-wave velocity model increased by 5%', 'P-wave velocity model increased by 2.5%', 'Unperturbed P-wave velocity model', 'P-wave velocity model decreased by 2.5%', 'P-wave velocity model decreased by 5%')
legend('Location','eastoutside')

Réponse acceptée

Stephan
Stephan le 1 Avr 2019
Modifié(e) : Stephan le 1 Avr 2019
Hi,
try:
clf
clc
clear all
close all
% DATA
Depth= [0 2 4 6 8 12 16 20 24 28 30 32 36 40];
% P-waves
vp_upt= [3.27 5.75 5.85 5.9 5.91 6.15 6.5 6.84 6.84 6.84 6.84 7.34 7.89 7.89];
vp_pve_5= [3.4335 6.0375 6.1425 6.195 6.2055 6.4575 6.825 7.182 7.182 7.182 7.182 7.707 8.2845 8.2845];
vp_pve_25=[3.35175 5.89375 5.99625 6.0475 6.05775 6.30375 6.6625 7.011 7.011 7.011 7.011 7.5235 8.08725 8.08725];
vp_nve_5=[3.1065 5.4625 5.5575 5.605 5.6145 5.8425 6.175 6.498 6.498 6.498 6.498 6.973 7.4955 7.4955];
vp_nve_25=[3.18825 5.60625 5.70375 5.7525 5.76225 5.99625 6.3375 6.669 6.669 6.669 6.669 7.1565 7.69275 7.69275];
% S-waves
vs_upt= [1.91 3.36 3.42 3.44 3.45 3.59 3.79 3.99 3.99 3.99 3.99 4.28 4.61 4.61];
vs_pve_5= [2.0055 3.528 3.591 3.612 3.6225 3.7695 3.9795 4.1895 4.1895 4.1895 4.1895 4.494 4.8405 4.8405];
vs_pve_25=[1.95775 3.444 3.5055 3.526 3.53625 3.67975 3.88475 4.08975 4.08975 4.08975 4.08975 4.387 4.72525 4.72525];
vs_nve_25=[1.86225 3.276 3.3345 3.354 3.36375 3.50025 3.69525 3.89025 3.89025 3.89025 3.89025 4.173 4.49475 4.49475];
vs_nve_5=[1.8145 3.192 3.249 3.268 3.2775 3.4105 3.6005 3.7905 3.7905 3.7905 3.7905 4.066 4.3795 4.3795];
% plot data
% colours
c_blue=[0 102 204]/255;
c_light_b=[0 255 255]/255;
c_green=[88 171 45]/255;
c_yellow=[255 220 15]/255;
c_red=[207 46 49]/255;
plot(vs_pve_5, -Depth,'Color', c_blue,'Linewidth',2)
hold on
plot(vs_pve_25,-Depth,'Color',c_light_b,'Linewidth',2);
plot(vs_upt, -Depth,'Color',c_green,'Linewidth',2);
plot(vs_nve_25,-Depth,'Color',c_yellow,'Linewidth',2);
plot(vs_nve_5,-Depth,'Color',c_red,'Linewidth',2);
% % add p -wave models
plot(vp_pve_5,-Depth,'Color',c_blue,'Linewidth',2);
plot(vp_pve_25,-Depth,'Color',c_light_b,'Linewidth',2);
plot(vp_upt,-Depth,'Color',c_green,'Linewidth',2);
plot(vp_nve_25,-Depth,'Color',c_yellow,'Linewidth',2);
plot(vp_nve_5,-Depth,'Color',c_red,'Linewidth',2);
% axis
%set(gca, 'FontName','Helvetica','FontSize', 14);
title(' 1-D Velocity Models')
xlabel('Velocity (km/s)')
ylabel('Depth (km)')
legend ('S-wave velocity model increased by 5%', 'S-wave velocity model increased by 2.5%','Unperturbed S-wave velocity model','S-wave model decreased by 2.5%','S-wave velocity model decreased by 5%', 'P-wave velocity model increased by 5%', 'P-wave velocity model increased by 2.5%', 'Unperturbed P-wave velocity model', 'P-wave velocity model decreased by 2.5%', 'P-wave velocity model decreased by 5%')
legend('Location','eastoutside')
result is:
colors.PNG
Best regards
Stephan
  1 commentaire
P_L
P_L le 1 Avr 2019
Hi Stephen Thank you so much - was over complicating the problem instead of making it simpler.
Many thanks again!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by