Minor Tick Marks Don't Render Consistently
2 views (last 30 days)
Show older comments
When I adjust the size of the plot window, the minor ticks on the x-axis dissappear. You can recreate the issue with the following code, where the first figure doesn't render the minor x ticks and the second figure does.
Is there a way to force the first figure to render the ticks without changing the style of the figure?
figure(1)
x=[1 10 100];
y =[1 10 100];
plot(x,y)
axis([1e-3 1e3 1e1 1e3])
set(gca, 'YScale', 'log')
set(gca, 'XScale', 'log')
set(gca,'FontSize',16, 'FontName', 'arial' )
figure(2)
figure('units','normalized','position',[.1 .1 .4 .4])
x=[1 10 100];
y =[1 10 100];
plot(x,y)
axis([1e-3 1e3 1e1 1e3])
set(gca, 'YScale', 'log')
set(gca, 'XScale', 'log')
set(gca,'FontSize',16, 'FontName', 'arial' )
0 Comments
Answers (2)
Massimo Zanetti
on 7 Oct 2016
Yes there is a simple way. Take control of ticks length. See last code line:
figure(1)
x=[1 10 100];
y =[1 10 100];
plot(x,y)
axis([1e-3 1e3 1e1 1e3])
set(gca, 'YScale', 'log')
set(gca, 'XScale', 'log')
set(gca,'FontSize',16, 'FontName', 'arial' )
%control ticks length
set(gca,'ticklength',2*get(gca,'ticklength'))
Shubham
on 2 Sep 2024
Hi Bsol,
The issue you're encountering with the disappearance of minor ticks when resizing the plot window is likely due to MATLAB's automatic adjustment of axis ticks based on the figure size. When the figure is too small, MATLAB may choose not to display minor ticks to prevent clutter.
To ensure that minor ticks are always displayed regardless of the figure size, you can explicitly enable them using the gca properties. Here's how you can modify your code to force the display of minor ticks:
% First figure
figure(1)
x = [1 10 100];
y = [1 10 100];
plot(x, y)
axis([1e-3 1e3 1e1 1e3])
set(gca, 'YScale', 'log')
set(gca, 'XScale', 'log')
set(gca, 'FontSize', 16, 'FontName', 'arial')
% Force the display of minor ticks
set(gca, 'XMinorTick', 'on', 'YMinorTick', 'on')
% Second figure
figure(2)
figure('units', 'normalized', 'position', [.1 .1 .4 .4])
x = [1 10 100];
y = [1 10 100];
plot(x, y)
axis([1e-3 1e3 1e1 1e3])
set(gca, 'YScale', 'log')
set(gca, 'XScale', 'log')
set(gca, 'FontSize', 16, 'FontName', 'arial')
% Force the display of minor ticks
set(gca, 'XMinorTick', 'on', 'YMinorTick', 'on')
Explanation
- XMinorTick and YMinorTick: These properties control the display of minor ticks on the x-axis and y-axis, respectively. Setting them to 'on' ensures that minor ticks are displayed regardless of the figure size.
- Consistency: Applying these settings to both figures ensures that minor ticks are consistently displayed across different figure sizes and styles.
By explicitly enabling minor ticks, you should be able to maintain their visibility even when the figure size is adjusted.
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!