switching x and y axes

69 visualizaciones (últimos 30 días)
melody Sharifi
melody Sharifi el 24 de Feb. de 2017
Editada: dpb el 26 de Feb. de 2017
I have a 166x180 concentration matrix. 166 is number of timesteps and 188 is elevation of nods in a box. I wrote this code to read each row from 1 to 166 and plot it and create a movie from concentration plots. I would like to have elevation as vertical axis and concentration between 0 and 1 as my horizontal axis but now with this code I get opposite so I would like to switch x and y axes. does anybody have any suggestion? I transposed the matrix but it didnt help. I dont want to use view function. Thanks for your help.
NumTimeSteps=166;
concentrationfile=port_conc';
fh=figure;
for i=1:NumTimeSteps,
plot(concentrationfile(:,i))
%view(90,90)
hold
set(gca,'YDir','reverse')
cmap = jet;
colormap (cmap)
xlim([0 180])
ylim([0 1])
colorbar('vert');
if 1<=i && i<2
title(sprintf('Concentration with time: Time %i min', i ));
elseif 2<=i && i<50
title(sprintf('Concentration with time: Time %i min', 15+((i-2)*15 )));
elseif 50<=i && i<NumTimeSteps
title(sprintf('Concentration with time: Time %i min', 720+((i-49)*240 )));
end
xlabel('Concentration');
ylabel('height of box');
hold off
som(i) = getframe(fh);
%close(fh);
end
outpre = sprintf(('%s_%s with time'),port_conc,'LGB');
fileavi=strcat(outpre,'.avi');
movie2avi(som,fileavi,'colormap',cmap,'fps',2,'videoname',strcat('LGB Concentration:',outpre),'quality',75)

Respuestas (1)

dpb
dpb el 24 de Feb. de 2017
Editada: dpb el 26 de Feb. de 2017
concentrationfile=port_conc';
for i=1:NumTimeSteps,
plot(concentrationfile(:,i))
...
The above plots each column of the array versus the ordinal number of observations as you know.
To plot the elevation as vertical axis and concentration as the horizontal axis you need the data for each of the 188 node heights from somewhere (or are they just 1:188?) and then call plot with the two-argument form instead of just one...
for i=1:NumTimeSteps
plot(concentrationfile(:,i),elevation)
...
where I've just used elevation as a placeholder variable name for that data vector (I presume it's the same nodes each time step? If so, it's a constant, if not, then it is also 2D and needs to be addressed for each time step like the concentration data).
If the concentration data you have are absolute but you want them scaled, is the scaling to be relative to the maximum observed or some outside arbitrary value? Either way, just divide the vector by that value before plotting it...
for i=1:NumTimeSteps
plot(concentrationfile(:,i)/ConcMaxValue,elevation)
...
ADDENDUM Post comment below--
N=size(port_conc,2);
plot(port_conc.',1:N)
set(gca,'ydir','reverse')
yields
which I think duplicates your figure after the view(90,90) exercise?
Note the reversal of role in the plot command with the Y being a single vector of 1:length(eachLine) and the concentration vectors (by column) playing the role as the X variable. But still, isn't there some actual physical dimension value associated with the 180 node points?
I note if one does
set(gca,'xscale','log'
there seems to be something kinda' funky going on that's hidden by the linear scale for the latter portion of the time series. You might want to do some further investigations there to see if everything really is what you think it is.
Try
set(gca,'xscale','log')
xlim([1E-20 1])
and see what you think...
ADDENDUM 2
While the above plots all the lines on a single axis to see what the data look like, the same thing applies re: argument order and content to each time observation to swap the axes to make the frames for the movie...
  3 comentarios
melody Sharifi
melody Sharifi el 24 de Feb. de 2017
Editada: dpb el 26 de Feb. de 2017
clc
NumTimeSteps=166;
concnntrationfile=port_conc;
fh=figure;
for i=1:NumTimeSteps,
plot(concentrationfile(i,:))
view(90,90)
hold
set(gca)
xlim([0 180])
ylim([0 1])
title(sprintf('Concentration with time: Time step number %i', i ));
xlabel('height of boxConcentration');
ylabel('Concentration');
hold off
som(i) = getframe(fh);
%close(fh);
end
%movie(som)
outpre = sprintf(('%s_%s with time'),port_conc,'LGB');
fileavi=strcat(outpre,'.avi');
movie2avi(som,fileavi,'fps',2,'videoname',strcat('LGB Concentration:',outpre),'quality',75)
dpb
dpb el 24 de Feb. de 2017
Editada: dpb el 24 de Feb. de 2017
"I have 166 timesteps(rows) and 188 nodes(column) in a cross section of a sandbox..."
Yes, and your initial posting said "188 is elevation of nodes in a box" and you wanted to plot the elevation (188 values) as the ordinate rather than the ascissa (166 time values) as it is when you use the single-variable form of plot.
Do you not have values for the elevations of these 188 node locations in the box at which the data were recorded somewhere? Would seem a normal thing to have.
Even if you don't and continue to just use the implied 1:188 values, then
plot(concentration(i,:),[1:length(concentration(i,:))])
will plot the concentration as the ascissa values instead of on the ordinate (y) axis. It may be necessary to use the reverse 'ydir' property on the y-axis to reproduce view(90,90); I use it so rarely forget its actual orientation; it may be reversed in direction vis a vis plot above, but that's easily rectified.
I still would have to think there's some geometry data somewhere that can be associated with the node numbers...
ADDENDUM Simple illustration...
x=1:10; y=x.^3; % dummy data
subplot(3,1,1) % make three small plots for comparison
plot(y) % plot just y vs 1:N (a la your concentration vector)
title('One argument plot call')
subplot(3,1,2) % now same thing but add your view statement to compare
plot(y), view(90,90)
title('One argument plot with view(90,90)')
subplot(3,1,3) % now plot but put y on x axis instead...
plot(y,x)
set(gca,'ydir','reverse') % reverse the y axis to match view
title('Two argument plot & reverse yaxis')
The above produces--
Note the last two are identical and that all it takes is using both an x,y vector in plot. It uses the first argument if both are given as the independent value, but it assumes if there's only one that it's the ordinate (dependent) variable just against an ordinal value rather than some actual x.
Now, I'm asking as the side question, what is the actual x of your data and why not use that instead of 1:N if it exists?

Iniciar sesión para comentar.

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by