Need help flipping axis values
조회 수: 13 (최근 30일)
이전 댓글 표시
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:

This is what I am trying to accomplish:

댓글 수: 0
답변 (2개)
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
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
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:

댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
