Display Log scale on y axis of graph

조회 수: 4 (최근 30일)
James
James 2011년 10월 2일
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!!

답변 (2개)

Rick Rosson
Rick Rosson 2011년 10월 2일
>> doc semilogy
  댓글 수: 3
Rick Rosson
Rick Rosson 2011년 10월 2일
1. Please read the documentation
2. Please try it. It works.
James
James 2011년 10월 2일
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??

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


Harry MacDowel
Harry MacDowel 2011년 10월 2일
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
James
James 2011년 10월 7일
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 2011년 10월 8일
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.

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

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by