Problem with a plot

2 次查看(过去 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 中查找有关 Graphics Object Properties 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by