set the tick format of y axis

8 Ansichten (letzte 30 Tage)
min lee
min lee am 7 Okt. 2024
Beantwortet: Star Strider am 7 Okt. 2024
How can I set the format of the ticks of the y axis?
I want to change the upper one to the lower one, as the former is too wide in space.
  1 Kommentar
Rahul
Rahul am 7 Okt. 2024
Hi @min lee, you can use 'ylim' function to set upper and lower bounds of the y-axis in a plot:
dat = 0.008*rand(1, 5); % Sample random data
plot(dat)
ylim([0 0.008]) % Set any arbitrary limit
Here's a compact plot, with suitable limits:
plot(dat)
ylim([min(dat) max(dat)]) % Set compact limits

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 7 Okt. 2024
In the Numeric Ruler Properties documentation, see the section on Exponent.
x = linspace(0, 1);
y1 = sin(2*pi*x);
y2 = cos(2*pi*x)*1E-2;
figure
yyaxis left
plot(x, y1)
yyaxis right
plot(x, y2)
grid
figure
yyaxis left
plot(x, y1)
yyaxis right
plot(x, y2)
grid
Ax = gca;
Ax.YAxis(2).Exponent = -3;
Experiment with your own data. Note that you will have to specify the second y-axis to use it with your plot.
If I had your data and code, I could do this directly using them.
.

Weitere Antworten (3)

Voss
Voss am 7 Okt. 2024
set(gca().YAxis,'Exponent',-3)

Walter Roberson
Walter Roberson am 7 Okt. 2024

Shivam Gothi
Shivam Gothi am 7 Okt. 2024
Hello @min lee,
You can achieve the desired xtick format in MATLAB. In order to demonstrate this consider the code:
% Here, I will demonstrate how to express the xticks and yticks in exponent form.
x=100:100:2000;
y=100:100:2000;
plot(x,y)
ax = gca;
ax.XAxis.Exponent = 2;
ax.YAxis.Exponent = 2;
You can refer to the following link to get more information:
I hope it helps!

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by