Borrar filtros
Borrar filtros

How can I make area plots where the explaining variable goes horisontally and not vertically from the x axis?

5 visualizaciones (últimos 30 días)
Hi community,
I have a question regarding the use of the area plotting function in matlab. I have some element oxides say SiO2, Fe2O3, Al2O3 and I want to plot their temporal evolution against the height of a column.
When I use the area function, it plots each point vertically on thefrom the top of the X-variable line and down to the respective y-value. What I basically want is that MatLab plots each Y value in a horizontaly fashion to the respective x value. Basically figure 1 rotated 90 degrees right.
Does anyone know how to do this?
Cheers
Julius
code:
%variables:
SiO2 = AGP1.SiO2./(AGP1.SiO2+AGP1.Al2O3+AGP1.Fe2O3)
Fe2O3= AGP1.Fe2O3./(AGP1.SiO2+AGP1.Al2O3+AGP1.Fe2O3)
Al2O3 = AGP1.Al2O3./(AGP1.SiO2+AGP1.Al2O3+AGP1.Fe2O3)
Code:
% elements and depth
elements = [SiO2 Fe Al2O3]
depth = [AGP1.SampleDepth AGP1.SampleDepth AGP1.SampleDepth]
subplot(1,2,1)
test = [SiO2 Fe Al2O3]
depth = [AGP1.SampleDepth AGP1.SampleDepth AGP1.SampleDepth]
area(depth,elements)
% set(gca,'Ylim',[45 165])
set(gca,'YDir','reverse')
title('area(depth,elements)')
xlabel('depth in m')
ylabel('element oxide %')
subplot(1,2,2)
test = [SiO2 Fe Al2O3]
depth = [AGP1.SampleDepth AGP1.SampleDepth AGP1.SampleDepth]
area(elements,depth)
% set(gca,'Ylim',[45 165])
set(gca,'YDir','reverse')
title('area(elements,depth)')
ylabel('depth in m')
xlabel('element oxide %')
What I have:
What I have
What I want:
This fig. is rotated manually

Respuestas (1)

Avni Agrawal
Avni Agrawal el 14 de Feb. de 2024
Hi Julius,
I understand that you want to rotate your area plot by 90 degrees i.e depth is on the y-axis and the element oxides are on the x-axis. The `area` function in MATLAB plots the area between the curve and the x-axis. To rotate the plot, you can use the `area` function with the depth as the x-axis values and the element oxides as the y-axis values, and then switch the labels for the x-axis and y-axis.
Here is how you can adjust your code to achieve this:
% Assuming that SiO2, Fe2O3, and Al2O3 have been calculated correctly as fractions
% Elements and depth
elements = [SiO2, Fe2O3, Al2O3];
depth = AGP1.SampleDepth; % Assuming SampleDepth is a column vector
% Create the area plot with depth as the 'x-axis' and elements as the 'y-axis'
subplot(1, 2, 1);
area(depth, elements, 'LineStyle', 'none'); % 'LineStyle', 'none' removes the lines between stacked areas
% Reverse the direction of the depth axis to go from top to bottom
set(gca, 'XDir', 'reverse');
% Title and labels (note that the labels are swapped)
title('Temporal Evolution of Element Oxides');
ylabel('Element Oxide %');
xlabel('Depth in m');
% For the second subplot, if you want to plot the same thing, you can repeat the process
subplot(1, 2, 2);
area(depth, elements, 'LineStyle', 'none');
set(gca, 'XDir', 'reverse');
title('Temporal Evolution of Element Oxides');
ylabel('Element Oxide %');
xlabel('Depth in m');
In the code above, the repeated lines are removed and used 'XDir' to reverse the x-axis (which is now representing the depth). Also, I've added 'LineStyle' to 'none' to remove the lines between the stacked areas, which is common in geochemical plots. Adjust the title and axis labels to match your data and the story you want to tell with your plot.
I hope this helps.

Categorías

Más información sobre Probability Distributions en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by