Hello everyone,
I would like to make a plot of 3 arrays of data into one figure. The y axis shows the depth in cm and the x axis should show the thickness of the layers, the density of the layers and the particle size of the layers. The particle size ranges from 0 to 31, the density from 1 to 1.4 and the thickness of the layers from 0 to 3. I would like to show the labels of every different data type with different colours. Also they should be same width. The plot that I have now causes the density to almost be a straight verticle line.
Depth_SW_N_LLM=0:0.1:8.2;
Depth_SW_N_LLM=Depth_SW_N_LLM';
TL_SW_N_LLM=zeros(83,1); %Thickness Layers
TL_SW_N_LLM(1:21,1)=2;
TL_SW_N_LLM(22:27,1)=0.6;
TL_SW_N_LLM(28:41,1)=1.4;
TL_SW_N_LLM(42:54,1)=1.3;
TL_SW_N_LLM(54:83,1)=2.9;
D_SW_N_LLM=zeros(83,1); %Density Layers
D_SW_N_LLM(1:21,1)=1;
D_SW_N_LLM(22:27,1)=1.0466;
D_SW_N_LLM(28:41,1)=1.0498;
D_SW_N_LLM(42:54,1)=1.2659;
D_SW_N_LLM(54:83,1)=1.34269;
PS_SW_N_LLM=zeros(83,1); %PS Layers
PS_SW_N_LLM(1:21,1)=0;
PS_SW_N_LLM(22:27,1)=16.755;
PS_SW_N_LLM(28:41,1)=17.276;
PS_SW_N_LLM(42:54,1)=35.87;
PS_SW_N_LLM(54:83,1)=30.897;
SW_N_L_Matrix=[Depth_SW_N_LLM,TL_SW_N_LLM,D_SW_N_LLM,PS_SW_N_LLM];
figure
plot(SW_N_L_Matrix(:,2),SW_N_L_Matrix(:,1))
set(gca, 'YDir','reverse')
set(gca, 'XAxisLocation', 'top')
hold on
plot(SW_N_L_Matrix(:,3),SW_N_L_Matrix(:,1))
hold on
plot(SW_N_L_Matrix(:,4),SW_N_L_Matrix(:,1))
set(gca, 'XTIck', [0:5:30])
grid on
Could anyone please help me to make a nice plot out of this?

 Réponse acceptée

Adam Danz
Adam Danz le 11 Avr 2019
This is a bit hacky but achieves what you're describing.
First I normalize all of your x-coordinates to values between 0:1.
Then I create the x-tick labels. You can reformat them as needed (number of decimals, etc). I also included a final label that explains what each row of values mean.
The data is then plotted in normalized coordinates along the x axis so the min and max values range from 0:1. The x tick labels must be rotated so they don't overlap.
% Normalize all x values (columns 2:4)
SW_N_L_Matrix_norm = (SW_N_L_Matrix(:,2:4) - min(SW_N_L_Matrix(:,2:4),[],1)) ./ range(SW_N_L_Matrix(:,2:4), 1);
% Create x-tick labels
nTicks = 6; %number of ticks
ticVals = [ linspace(min(SW_N_L_Matrix(:,2)), max(SW_N_L_Matrix(:,2)), nTicks);
linspace(min(SW_N_L_Matrix(:,3)), max(SW_N_L_Matrix(:,3)), nTicks);
linspace(min(SW_N_L_Matrix(:,4)), max(SW_N_L_Matrix(:,4)), nTicks);
];
% ticStr = strsplit(sprintf('%.2f\n%.2f\n%.2f|', ticVals(:)),'|');
ticStr = strsplit(sprintf('%.1f__%.2f__%.1f|', ticVals(:)),'|');
ticStr(end) = {'Thk__Dens__PSz'}; %x tick 'legend'
% Create the plot
figure
plot(SW_N_L_Matrix_norm(:,1),SW_N_L_Matrix(:,1))
set(gca, 'YDir','reverse')
set(gca, 'XAxisLocation', 'top')
hold on
plot(SW_N_L_Matrix_norm(:,2),SW_N_L_Matrix(:,1))
plot(SW_N_L_Matrix_norm(:,3),SW_N_L_Matrix(:,1))
% Set the x tick labels
xlim([0,1.05])
set(gca, 'XTick', [linspace(0,1,nTicks), 1.05], 'XTickLabel', ticStr, 'XTickLabelRotation', 90)
grid on
190411 120732-Figure 1.jpg

2 commentaires

Lodewijk Pleij
Lodewijk Pleij le 12 Avr 2019
Thank you adam, this helped a lot. Could you explain me how I can make the range for thickness start from 0?
Adam Danz
Adam Danz le 12 Avr 2019
Modifié(e) : Adam Danz le 12 Avr 2019
I normalized all of your x-values using this method:
dataNorm = (data - min(data)) ./ range(data);
If you want your normalization to start at 0 rather than the minimum value, then do this:
dataNorm2 = data ./ max(data);
But then you have the change the labels too
linspace(min(SW_N_L_Matrix(:,3)), max(SW_N_L_Matrix(:,3)), nTicks); %from this
linspace(0, max(SW_N_L_Matrix(:,3)), nTicks); %to this

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Labels and Annotations dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by