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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by