Need help flipping axis values

12 次查看(过去 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