Different tick values on same axis

조회 수: 4 (최근 30일)
Alexandra Roxana
Alexandra Roxana 2023년 1월 4일
댓글: Star Strider 2023년 1월 4일
I want to use xticks using different steps. From a to a+g the step dxs, from a+g to b-g the step dxf and from b-g to b again the step dxs. Can it be used in the same command? Thank you in advance.
a=0;
b=4;
c=0;
d=6;
g=1;
dxs=0.2;
dxf=0.25;
dy=0.5;
figure(1)
plot([a b b a a],[c c d d c])
hold on
axis([a-1 b+1 c-1 d+1])
hold on
plot([a+g b-g b-g a+g a+g],[c c d d c])
hold on
axis([a+g-1 b-g+1 c-1 d+1])
grid on
axis tight
axis equal
xticks([a:dxs:a+g])
yticks([c:dy:d])

채택된 답변

Star Strider
Star Strider 2023년 1월 4일
편집: Star Strider 2023년 1월 4일
See if the xticks call in:
xticks([a+g:dxf:b-g (b-g+dxs):dxs:b])
does what you want —
a=0;
b=4;
c=0;
d=6;
g=1;
dxs=0.2;
dxf=0.25;
dy=0.5;
figure(1)
plot([a b b a a],[c c d d c])
hold on
axis([a-1 b+1 c-1 d+1])
hold on
plot([a+g b-g b-g a+g a+g],[c c d d c])
hold on
axis([a+g-1 b-g+1 c-1 d+1])
grid on
axis tight
axis equal
xticks([a:dxs:a+g (a+g)+dxf:dxf:b-g (b-g)+dxs:dxs:b]) % NEW
Check = xticks % Check Values (Optional)
Check = 1×19
0 0.2000 0.4000 0.6000 0.8000 1.0000 1.2500 1.5000 1.7500 2.0000 2.2500 2.5000 2.7500 3.0000 3.2000 3.4000 3.6000 3.8000 4.0000
% xticks([a:dxs:a+g])
yticks([c:dy:d])
The xticks argument values have to increase, so two adjacent values of (b-g) are not permitted.
.
  댓글 수: 5
Alexandra Roxana
Alexandra Roxana 2023년 1월 4일
I've already put it, no worries!
Star Strider
Star Strider 2023년 1월 4일
Thank you!

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

추가 답변 (1개)

Bora Eryilmaz
Bora Eryilmaz 2023년 1월 4일
편집: Bora Eryilmaz 2023년 1월 4일
You can generate a ticks vector, which should be sorted and with unique elements:
a=0;
b=4;
c=0;
d=6;
g=1;
dxs=0.2;
dxf=0.25;
dy=0.5;
figure(1)
plot([a b b a a],[c c d d c])
hold on
plot([a+g b-g b-g a+g a+g],[c c d d c])
grid on
axis tight
axis equal
% Set axis limits
ax = gca;
ax.XLim = [a b];
ax.YLim = [c d];
% Ticks vectors
x_ticks = unique([a:dxs:(a+g), (a+g):dxf:(b-g), (b-g):dxs:b], 'stable');
xticks(x_ticks)
yticks([c:dy:d])

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by