我在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标签范围从-0.0025到0.0005?谢谢!
您可以尝试使用sprintf手动设置刻度标签:
yt = get(gca,'YTick');
set(gca,'YTickLabel', sprintf('%.4f|',yt))
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;
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');
函数ticklabelformat(hAxes,axName,format)由Y. Altman编写,可以在以下网址找到:http://www.mathworks.com/matlabcentral/fileexchange/36254-ticklabelformat-set-a-dynamic-format-of-axes-tick-labels,或通过谷歌搜索“ticklabelformat matlab”获得。我稍微修改了它,将第105行更改为:
tickLabels = arrayfun(@(x)(FormatNumberScalarInputStrOutput`(x,format)),tickValues,'UniformOutput',false);`
tickLabels = arrayfun(@(x)(sprintf(format,x)),tickValues,'UniformOutput',false);
这个修改提供了千位分隔符功能,实现方法是通过函数 y = NumberFormatter( Numbers , FormatPattern ) ,作者是 S. Lienhard,该函数也可以在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));
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)
您需要编写以下内容:
set(gcf, 'renderer', 'zbuffer')
%f
,它仍然为整个轴使用全局指数。 - Timmmm