Problem with a plot

1 Ansicht (letzte 30 Tage)
Francesco
Francesco am 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 Kommentar
the cyclist
the cyclist am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (3)

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

Melden Sie sich an, um zu kommentieren.


Francesco
Francesco am 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'))

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by