Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing scientific notation in the tick label of a Matlab plot

Tags:

plot

label

matlab

I have made a plot in Matlab, using:

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

However, the tick labels on the y axis are generated in scientific notation:

Scientific Notation on y-axis

Is there any way I can remove the scientific notation and just have the y labels range from -0.0025 to 0.0005? Thanks!

like image 786
Andrew Avatar asked May 04 '12 18:05

Andrew


People also ask

How do I get rid of E+ in matlab?

you can use "format short g" command in the start of the code. I am a fresher in matlab but as far as i know it can help to get rid of e in the answer.

How could you remove scientific notation from your plot axes?

First of all, create a vector and its plot using plot function. Then, use options(scipen=999) to remove scientific notation from the plot.

How do I remove a tick label in matlab?

Direct link to this answerTickLength = [0 0]; This will allow you to keep the labels but remove the tick marks on only the x-axis.

What is tick labels in matlab?

xticks( ticks ) sets the x-axis tick values, which are the locations along the x-axis where the tick marks appear. Specify ticks as a vector of increasing values; for example, [0 2 4 6] . This command affects the current axes. xt = xticks returns the current x-axis tick values as a vector.


2 Answers

You could try to manually set the tick labels yourself using sprintf:

yt = get(gca,'YTick');
set(gca,'YTickLabel', sprintf('%.4f|',yt))
like image 177
robince Avatar answered Nov 02 '22 21:11

robince


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;
like image 30
GHH Avatar answered Nov 02 '22 21:11

GHH