How to create a uniform y-tick interval in subplots

조회 수: 25 (최근 30일)
Richard Rees
Richard Rees 2020년 3월 23일
댓글: Richard Rees 2020년 3월 24일
Hello, I am wondering how to create a uniform y tick interval between subplots in matlab, that takes into consideration the ylimits?
Lets say that I only wanted there to be only 4 intervals per plot and only rounded ytick labels apparement, all the precise same position per subplot. I tried to do this calculating the min and max's for each subplot and dividng the absolute difference between each by 4, unfortunately it didn't work out. Below is the graph that is created without any interference by myself. If anyone is familar with TecPlot, I want to make the axis values 'nice'.
  댓글 수: 1
Stijn Haenen
Stijn Haenen 2020년 3월 23일
You can change the thick labels with:
h=figure();
plot(1:10)
h.CurrentAxes.YTick=[1,3,6]
In this example ythicks: 1, 3, 6 are shown.

댓글을 달려면 로그인하십시오.

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 3월 23일
Something like this works. Note that you'll have some challenges because most of your y values are very small, so it might not look quite like you'd expect.
p1 = rand([50,1])*5.5-1.1;
p2 = rand([50,1])*3.5e-6 - 3e-6;
p3 = rand([50,1])*0.5e-6 + 3.8e-6;
p4 = rand([50,1])*4.1e-7 - 3e-7;
p5 = rand([50,1])*0.2e-6 - 3.45e-6;
subplot(5,1,1)
plot(p1)
yval = ylim(gca);
set(gca,'YTick',linspace(yval(1),yval(2),5),"YTickLabel",round(linspace(yval(1),yval(2),5)))
subplot(5,1,2)
plot(p2)
yval = ylim(gca);
set(gca,'YTick',linspace(yval(1),yval(2),5),"YTickLabel",round(linspace(yval(1),yval(2),5),6))
subplot(5,1,3)
plot(p3)
yval = ylim(gca);
set(gca,'YTick',linspace(yval(1),yval(2),5),"YTickLabel",round(linspace(yval(1),yval(2),5),6))
subplot(5,1,4)
plot(p4)
yval = ylim(gca);
set(gca,'YTick',linspace(yval(1),yval(2),5),"YTickLabel",round(linspace(yval(1),yval(2),5),7))
subplot(5,1,5)
plot(p5)
yval = ylim(gca);
set(gca,'YTick',linspace(yval(1),yval(2),5),"YTickLabel",round(linspace(yval(1),yval(2),5),6))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by