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 Center および File ExchangeGeographic Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by