我还让我打的情节轴固定的概念,而不是科学记数法显示。对我而言,最令人沮丧的是,即使我将刻度标签手动重新分配到固定标记后,“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));
哎呀,你是只有几秒快...... ;-)。无论如何,你应该用“ytick”和“yticklabel”替换“xtick”和“xticklabel”。第二行末尾的x应为xt。 –
:) - 正要接到电话时! – robince
第二行末尾的x仍然是错误的。应该读一下,我猜。 –