Need help flipping axis values

조회 수: 13 (최근 30일)
Chase Valo
Chase Valo 2019년 12월 17일
편집: Adam Danz 2019년 12월 18일
I am plotting a series of data from excel, however the values on the x & y axis are flipped.
This is what I currently have:
stuff.PNG
This is what I am trying to accomplish:
yee.PNG

답변 (2개)

Adam Danz
Adam Danz 2019년 12월 17일
편집: Adam Danz 2019년 12월 17일
Instead of plotting
plot(x,y)
plot
plot(y,x)
If you're using a different plotting function, the main idea is to just switch the x and y inputs.
If your input is a matrix, transpose it (which appears to be the case, judging from the axis ticks)
plot(x.')
  댓글 수: 2
Chase Valo
Chase Valo 2019년 12월 17일
Flipping x and y does give this:
u.PNG
However, the numbers for the x and y axis are still reversed and transposing has no effect
Adam Danz
Adam Danz 2019년 12월 17일
편집: Adam Danz 2019년 12월 18일
How did you get the the figure you shared in "what I want to accomplish"? Did you plot that in Matlab? Where did you get those data from?
One possibility is that you're dealing with different units between the two figures. For example, the x axis in your plot indicate units of meters while the y axis are m^-2. When I look at other irradiance plots, often times units are in nanometers in which case your values look OK. Here are examples where the range of values along the x and y axes are similar to yours.
My guess is that your data and plot are fine but something is off with the other plot you're trying to copy - probably the units or maybe the axis ticks labels are incorrect.

댓글을 달려면 로그인하십시오.


Star Strider
Star Strider 2019년 12월 17일
I am not certain what the problem may be.
Using your previous code:
%Constants:
h = 6.626e-34;
k = 1.381e-23;
c = 2.998e8;
t = 5800;
r_sun = 1.39e9/2;
r_earth = 1.5e11;
f_w = (r_sun/r_earth)^2;
%Function:
L_sun =@(l) f_w*((2*pi*h*c^2)./l.^5).*(1./(exp(h*c./(l*k*t))-1));
lambda = linspace(0.01, 3)*1E-6;
figure
plot(lambda, L_sun(lambda))
xt = get(gca, 'XTick');
set(gca, 'XTick',xt, 'XTickLabel',xt*1E+6)
xlabel('Wavelength (\mum)')
ylabel('Spectral Irradiance (Wm^{-2} \mum^{-1})')
text(1E-6, 1E9, '$\leftarrow L(\lambda) = f_{\nu} \frac{2\pi hc^2}{\lambda^2} \frac{1}{e^{\frac{something}{something else}-1}}$', 'Interpreter','latex', 'HorizontalAlignment','left')
produces:
1Need help flipping axis values - 21019 12 17.png

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by