Display Log scale on y axis of graph

Hi, if anybody could help me with this i would be really greatful, im trying to plot the blackbody radiation for a number of temperatures from 3 kelvin - 1million kelvin
However it is very hard to see the smaller plots due to the weights of the high temperatures, therefore i need the y axis to increase logarithmically WITHOUT getting the log of the data. so how can i change the axis????
thanks in advance, if you can answer this within a day you are my new hero!!

Respuestas (2)

Rick Rosson
Rick Rosson el 2 de Oct. de 2011
>> doc semilogy

3 comentarios

James
James el 2 de Oct. de 2011
how would i use this with say plot(lamda,intensity,'k-')? and would that just not just give me the log of my ydata
Rick Rosson
Rick Rosson el 2 de Oct. de 2011
1. Please read the documentation
2. Please try it. It works.
James
James el 2 de Oct. de 2011
used semilogy(lambda,b1,'r-') and variations of it a load of times now, fine it gives me a logarithmic axis but its takking a log of my data which is not what i want, iv only been using matlab for about a week, maybe im missing something??

Iniciar sesión para comentar.

Harry MacDowel
Harry MacDowel el 2 de Oct. de 2011
A log scale but not the log of your data, that is exactly what semilogy is doing.
In fact I think you are not stating your problem very clearly either. What do you really want?
If you have a log axis, but then your data is not logarithmic, do you mean that you don't want to transform the data through a calculation process of your own/the Matlab or, you want to plot the 'original' data under a log scale? That would be quite absurd since your data would be jam-packed into a bundle of dots 'collapsing' onto each other.
If you really want to do this, you can achieve it by transforming the axis. Do something like,
ylimit = [0,35];
ytic = [0 5 10 15 20 25 30 35];
ylimit2 = log(ylimit);
ytic2 = log(ytic);
ytic2str = str2num(ytic2');
ax1 = gca;
ax2 = axes('Position',get(ax1,'Position'),'Color','none');
set(ax2,'ylim',ylimit,'ytick',get(ax1,'ytick'),'xtick',get(ax1,'xtick'),'xticklabel',[],'yticklabel',ytic2str);

5 comentarios

James
James el 2 de Oct. de 2011
I know it might sound slightly absurd but when i was plotting plot(lamda,intensity,'k-') the intensity peaks (y axis) for different temperatures ranged from about 5 to 1e13. The different peaks have to be displayed on the same graph, so what was happening is that the large peaks drowned the small peaks so i cant see them....therefore i need to change the y axis into some kind of log scale so i will be able to see the top of each peak and its value.
i tried using that code but its/im getting stuck on
ytic2str = str2num(ytic2');
this is the error im getting--
??? Error using ==> str2num at 33
Requires string or character array input.
Error in ==> astromodel at 47
ytic2str = str2num(ytic2');
line 32 and 33 of my code is:
32---plot(lambda,b1,'r-');
33---title('Blackbody Radiation Density vs. Wavelenght');
b1 is the intensity as a function of lambda
Walter Roberson
Walter Roberson el 2 de Oct. de 2011
num2str() rather than str2num()
Harry MacDowel
Harry MacDowel el 3 de Oct. de 2011
sorry was writing that piece too fast I didn't notice it.
Yeah Walter got it there. It's num2str not str2num. Sorry.
James
James el 7 de Oct. de 2011
ye it compiles nicely but just seams to write over the numbers that are on the graph already.
heres what i have so far, maybe somebody can eventully fix it:
clear all;
h = 6.626e-34; % Planck's Constant = 4.135 x 10^-15 eV s
c = 3e8; % speed of light
T= 1000000; % kelvin
k= 1.38066e-23; % Boltzmann constant in J/K
lambda=0:1e-10:1e-5;
p=8*pi*h*c./(lambda.^5);
b1=p.*1./(exp(h*c./(lambda*k*T)-1));
b2=p.*1./(exp(h*c./(lambda*k*100000)-1));
b3=p*1./(exp(h*c./(lambda*k*10000)-1));
b4=p*1./(exp(h*c./(lambda*k*1000)-1));
b5=p*1./(exp(h*c./(lambda*k*100)-1));
b6=p*1./(exp(h*c./(lambda*k*2.7)-1));
ylimit = [0,35];
ytic = [0 5 10 15 20 25 30 35];
ylimit2 = log(ylimit);
ytic2 = log(ytic);
ytic2str = num2str(ytic2');
ax1 = gca;
ax2 = axes('Position',get(ax1,'Position'),'Color','none');
set(ax2,'ylim',ylimit,'ytick',get(ax1,'ytick'),'xtick',get(ax1,'xtick'),'xticklabel',[],'yticklabel',ytic2str);
plot(lambda,b1,'m-');
title('Blackbody Radiation Density vs. Wavelength');
xlabel('Wavelength [m]')
ylabel('Intensity');
hold on;
plot(lambda,b2,'y-');
plot(lambda,b3,'g-');
plot(lambda,b4,'c-');
plot(lambda,b5,'k-');
plot(lambda,b6,'r-');
legend('1000000K','100000K','10000K','1000K','100K','2.7K');
Harry MacDowel
Harry MacDowel el 8 de Oct. de 2011
yes that code is replacing the labels on the y-axis without altering anything in regard to the original plot or the data itself. That's why I am asking you in the first place, what do you want?
Please do realize that currently the ytic in the codes I given hasn't been altered by you either.
If you want to view the data on a log scale way above the limit of your current y data, please change the limit yourself and thus the ensuing codes.

Iniciar sesión para comentar.

Productos

Preguntada:

el 2 de Oct. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by