Different tick values on same axis
    8 views (last 30 days)
  
       Show older comments
    
    Alexandra Roxana
 on 4 Jan 2023
  
    
    
    
    
    Commented: Star Strider
      
      
 on 4 Jan 2023
            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])
0 Comments
Accepted Answer
  Star Strider
      
      
 on 4 Jan 2023
        
      Edited: Star Strider
      
      
 on 4 Jan 2023
  
      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)
% 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 Comments
More Answers (1)
  Bora Eryilmaz
    
 on 4 Jan 2023
        
      Edited: Bora Eryilmaz
    
 on 4 Jan 2023
  
      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])
See Also
Categories
				Find more on Axis Labels in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




