Problem with a plot

3 views (last 30 days)
Francesco
Francesco on 23 Jan 2012
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 Comment
the cyclist
the cyclist on 23 Jan 2012
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.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 23 Jan 2012
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 Comments
Francesco
Francesco on 23 Jan 2012
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 on 23 Jan 2012
You could use (e.g.) %.5g to constrain the label length.

Sign in to comment.

More Answers (3)

Francesco
Francesco on 24 Jan 2012
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 on 24 Jan 2012
You axes() with Position, but you do not ensure that the Units match.
  1 Comment
Francesco
Francesco on 24 Jan 2012
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

Sign in to comment.


Francesco
Francesco on 24 Jan 2012
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'))

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!