11

以下を使用して、Matlabでプロットを作成しました。

hold on
plot(t1,Dx1,'r')
xlabel('t (ps)')
ylabel('Deviation of coordinate from initial coordinate (Å)')
plot(t1,Dy1,'g')
plot(t1,Dz1,'b')
hold off

ただし、y軸の目盛りラベルは科学的記数法で生成されます。

y軸の科学的記数法

科学的記数法を削除して、yラベルの範囲を-0.0025から0.0005にする方法はありますか?ありがとう!

4

6 に答える 6

11

sprintfを使用して、自分で目盛りラベルを手動で設定してみることができます。

yt = get(gca,'YTick');
set(gca,'YTickLabel', sprintf('%.4f|',yt))
于 2012-05-04T18:53:24.857 に答える
5

軸を作成した後、これを追加してみてください。

ax = gca;
ax.YAxis.Exponent = 0;

次に例を示します。

x = 0:0.1:10;
y = 1000*x.^2;

%Plot with default notation:

subplot(1,2,1)
plot(x,y)


%Plot without exponent:

subplot(1,2,2)
plot(x,y)
ax = gca
ax.YAxis.Exponent = 0;
于 2017-02-07T02:43:00.730 に答える
4

また、プロット軸を科学的記数法ではなく固定記数法で表示することにも取り組みました。私にとって最も苛立たしい部分は、ティックラベルを手動で固定表記に再割り当てした後でも、「x10^4」ラベルがプロットボックスの端に残ることでした。最後に、上記の投稿のおかげで、フィギュアレンダラーで問題を追跡しました。私は「OpenGL」を使用していました。「zbuffer」に変更した場合、ティックラベルを手動でリセットすると、「x10^4」ラベルが適切に消えていました。これは、フォーマット「###、###。0」をy軸ラベルに適用し、ズーム/パンなどのときにyラベルを動的に更新するサンプルコードです。これは、 Matlabファイル交換。他の2つの関数を見つける場所は、関数例の下にコメントとして含まれています。

function []=TickFixExample()

figure %this one works
myRenderer='zbuffer';
set(gcf,'Renderer', myRenderer); 
axesh = axes();
set(gca,'YLim',[20000 20100]);
title(myRenderer)
ticklabelformat(gca,'y','###,###.0');

figure %this one doesn’t work
myRenderer='OpenGL';
set(gcf,'Renderer', myRenderer); 
axesh = axes();
set(gca,'YLim',[20000 20100]);
title(myRenderer)
ticklabelformat(gca,'y','###,###.0');

Y. Altmanによる関数ticklabelformat(hAxes、axName、format)は、http: //www.mathworks.com/matlabcentral/fileexchange/36254-ticklabelformat-set-a-dynamic-format-of-axes-tickにあります。 -ラベルまたはグーグルで' ticklabelformatmatlab '次のように105行目を変更して少し変更しました。

 tickLabels = arrayfun(@(x)(FormatNumberScalarInputStrOutput`(x,format)),tickValues,'UniformOutput',false);`

Altmanのバージョンの代わりに:

tickLabels = arrayfun(@(x)(sprintf(format,x)),tickValues,'UniformOutput',false);

この変更により、S。Lienhardによる関数y = NumberFormatter(Numbers、FormatPattern)による数千のコンマ区切り機能が提供されます。これもMatlabファイル交換で行われます。Lienhardコードの私の修正バージョンは、以下に完全に示されています。

function y = FormatNumberScalarInputStrOutput(Number ,FormatPattern)

 % adapted 12-2012 by D. Bourgoyne from NUMBERFORMATTER by S. Lienhard
% 
%   The pound sign (#) denotes a digit, the comma is a placeholder for the
%   grouping separator, and the period is a placeholder for the decimal
%   separator.
%   The pattern specifies leading and trailing zeros, because the 0
%   character is used instead of the pound sign (#).
% 
%   Examples:
%   NumberFormatter(rand(5),'0.000')
%   NumberFormatter(rand(5)*100,'###,###.000') 
import java.text.*
v = DecimalFormat(FormatPattern);
y = char(v.format(Number));
于 2012-12-14T18:36:19.223 に答える
1

このコードを使用して、y軸の目盛りラベルの形式を制御できます。このコードはticks_format.mに由来します。

%ここで優先ティックフォーマットを設定します。

y_formatstring = '%3.4f';

%これがコードです。

ytick = get(gca, 'ytick');
for i = 1:length(ytick)
    yticklabel{i} = sprintf(y_formatstring, ytick(i));
end
set(gca, 'yticklabel', yticklabel)
于 2012-05-04T18:57:42.380 に答える
1

次のように書く必要があります。

set(gcf, 'renderer', 'zbuffer')
于 2012-08-07T14:49:36.957 に答える
0

新しいバージョンのmatlab(2016b)では、関数ytickformatおよびxtickformatを使用して、ラベルの形式を簡単に変更できます。

于 2019-08-05T08:44:04.927 に答える