Problem with a plot

조회 수: 1 (최근 30일)
Francesco
Francesco 2012년 1월 23일
Hi all,
I'm working on a simulation for some misurement with a Thomson spectrometer and I'm having some issue with the plot layout. In x and y axis I have magnetic and electric deflection and I have other two axis on top and right giving momentum and energy info. I am not able to write the secondary tick label in the proper way: as defoult MatLab writes tick label as integer and a (x10^-12) at the end of the label but on the bottom of the screen. If I use: [code] set(gca, 'YTickLabel', num2str(get(gca,'YTick')','%d')) [\code]
it writes the tick label as "6.00000e^12" and I have some overlaps.
Moreover if I make the plot window bigger the secondary axes don't resize properly. Last the plot title is written too high...
Could somebody help me in fixing this bugs? Thanks
I can provide the code I wrote for the plot, if need
  댓글 수: 1
the cyclist
the cyclist 2012년 1월 23일
It would definitely be helpful for you to provide the code, ideally in a way that is distilled into the bare minimum that exhibits the problem.

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

채택된 답변

Walter Roberson
Walter Roberson 2012년 1월 23일
MATLAB does not default to writing the tick labels as integers, unless perhaps that is the default when you supply your own tick label in numeric form instead of string. If no tick labels are supplied, MATLAB dynamically formats tick labels.
What format do you want your tick label to come out as? Perhaps
set(gca, 'YTickLabel', num2str(get(gca,'YTick')','%g'))
  댓글 수: 2
Francesco
Francesco 2012년 1월 23일
You get right, thanks.
I'm still having overlap with the legend, but it's minor issure.
I can't understand why the plot title goes under the toolbar and the secondary axes don't resize.
Walter Roberson
Walter Roberson 2012년 1월 23일
You could use (e.g.) %.5g to constrain the label length.

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

추가 답변 (3개)

Francesco
Francesco 2012년 1월 24일
The code I used for plotting data is:
figure(1)
hplot = plot(.... )
xlabel(gca, 'Deflessione magnetica [m]'); % label lower x axis ylabel(gca,'Deflessione elettrica [m]'); %label left y axis
%%%% legend l=legend(hplot, ...); a=get(l,'children'); set(a(1:3:end),'MarkerSize',10);
%%%% Secondary x axis %set secondary x limit mv_max = (q*B*LB*L)/Rmcp;
%Layout instruction set(gca,'Box','off'); axesPosition = get(gca,'Position'); hNewAxes = axes('Position',axesPosition,... 'Color','none',... 'XAxisLocation','top',... 'Ytick', [],... 'Xlim', [0, mv_max],... 'Box','off');
xlabel(hNewAxes,'Momentum (H^+)'); %# Add a label to the top axis
set(gca, 'XTickLabel', num2str(get(gca,'XTick')','%g'))
title(['Calcolo approssimato interazione ioni campo magnetico B=', num2str(B), 'Tesla']);
%%%% Secondary y Axis as above

Walter Roberson
Walter Roberson 2012년 1월 24일
You axes() with Position, but you do not ensure that the Units match.
  댓글 수: 1
Francesco
Francesco 2012년 1월 24일
this is the reason why the secondary axis don't resize?
How to fix the problem?
Sorry, I'm a newbie in MatLab and programming

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


Francesco
Francesco 2012년 1월 24일
I tried with this code, but nothing change, whati is wrong?
set(gca,'Box','off');
axesUnits=get(gca,'Units');
axesPosition = get(gca,'Position');
hNewAxes = axes('Position',axesPosition,... 'Units', axesUnits,... 'Color','none',... 'XAxisLocation','top',... 'Ytick', [],... 'Xlim', [0, mv_max],... 'Box','off');
xlabel(hNewAxes,'Momentum (H^+)'); %
set(gca, 'XTickLabel', num2str(get(gca,'XTick')','%g'))

카테고리

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