Removing scientific notation in the tick label of a Matlab plot
I also fought with getting my plot axes to display in fixed notion instead of scientific notation. The most frustrating part for me was that the "x10^4" label would remain on the edge of the plot box even after I reassigned the tick labels manually to fixed notation. Finally, thanks to the post above I tracked the problem down the figure renderer. I was using 'OpenGL'. When I changed to 'zbuffer' the "x10^4" label would properly disappear when I manually reset the tick labels. Here's an example code that apples the format '###,###.0’ to the y-axis labels, and even dynamically updates the y-labels when you zoom/pan etc, thanks to two helpful functions I found on the Matlab File Exchange. The place to find the other two functions is included as comments below example function.
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');
function ticklabelformat(hAxes,axName,format) by Y. Altman, can be found at: http://www.mathworks.com/matlabcentral/fileexchange/36254-ticklabelformat-set-a-dynamic-format-of-axes-tick-labels or by googling 'ticklabelformat matlab' I modified it slightly by changing line 105 as follows:
tickLabels = arrayfun(@(x)(FormatNumberScalarInputStrOutput`(x,format)),tickValues,'UniformOutput',false);`
in lieu of Altman's version:
tickLabels = arrayfun(@(x)(sprintf(format,x)),tickValues,'UniformOutput',false);
that change provides for the thousands comma separator functionality by function y = NumberFormatter( Numbers , FormatPattern ) by S. Lienhard, also on Matlab File Exchange. My modified version of Lienhard code is given in full below:
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));
Try adding this after creating the axes:
ax = gca;
ax.YAxis.Exponent = 0;
Here is an example:
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;
You could try to manually set the tick labels yourself using sprintf:
yt = get(gca,'YTick');
set(gca,'YTickLabel', sprintf('%.4f|',yt))