Reputation: 132
I'm trying to draw plots with Matlab and the problem is that i want to fix the maximum value of y-axis to 8 . To help you understand me, look at this first example :
you can see that the maximum y value is 8. but when i try to draw this graph :
its maximum y value is 6 . i want to fix it for all examples to 8. how can i do it? here's my code for now :
data=importdata('C:/Users/Eden/Desktop/Calcul_accel/fichier_final.txt');
fig = figure(1);
x=data(:,2)
y=data(:,3)
p=plot(x,y)
set(p,'Color','red');
xlabel('Time(milliseconds)','FontSize',12,'FontWeight','bold','Color','b');
ylabel('Acceleration(g unit)','FontSize',12,'FontWeight','bold','Color','b')
thank you very much
Upvotes: 1
Views: 843
Reputation: 104464
Use ylim
if you just want to modify the y
axis.
Therefore, do this once your plot is already open:
ylim([0 8]);
This overrides the auto-scaling of the axes so that y
always spans between 0 to 8.
In general, @eigenchris mentioned to use axis
, which allows you to change the dynamic range of what is viewable in a plot for both the x
and y
axes. However, since you only want to change how the y
-axis is visualized, one call to ylim
is enough.
Upvotes: 2