2012-05-04 49 views
11

我已在Matlab阴谋的刻度标记科学记数法,使用:删除在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轴上的刻度标记Scientific Notation on y-axis

是否有任何方法可以删除科学记数法并且只有y标签的范围从-0.0025到0.0005?谢谢!

回答

9

您可以尝试手动设置刻度标记自己使用的sprintf:

yt = get(gca,'YTick'); 
set(gca,'YTickLabel', sprintf('%.4f|',yt)) 
+0

哎呀,你是只有几秒快...... ;-)。无论如何,你应该用“ytick”和“yticklabel”替换“xtick”和“xticklabel”。第二行末尾的x应为xt。 –

+1

:) - 正要接到电话时! – robince

+1

第二行末尾的x仍然是错误的。应该读一下,我猜。 –

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) 
2

你必须写:

set(gcf, 'renderer', 'zbuffer') 
+0

@Andrew我不知道该怎么解释,但它确实很有效! –

4

我还让我打的情节轴固定的概念,而不是科学记数法显示。对我而言,最令人沮丧的是,即使我将刻度标签手动重新分配到固定标记后,“x10^4”标签仍会保留在情节盒的边缘。最后,感谢上面的帖子,我跟踪了人物渲染器的问题。我正在使用'OpenGL'。当我更改为'zbuffer'时,手动重置刻度标签时,“x10^4”标签将正常消失。 下面是一个示例代码,将格式'###,###。0'应用于y轴标签,甚至在缩放/平移等时动态更新y标签,这要归功于我发现的两个有用功能Matlab文件交换。查找其他两个函数的地方包含在下面的示例函数中。

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,格式)由Y.奥特曼,可参见: http://www.mathworks.com/matlabcentral/fileexchange/36254-ticklabelformat-set-a-dynamic-format-of-axes-tick-labels 或通过使用Google '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 File Exchange上。我修改的林哈德代码版本 下面全给出:

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

下面是一个例子:

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)); 
3

尝试创建轴后加入这个

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; 
+1

我读了几十个答案,这是最好的!谢谢@GHH! – user1271772