Minor Tick Marks Don't Render Consistently

조회 수: 7 (최근 30일)
bsol
bsol 2016년 10월 7일
답변: Shubham 2024년 9월 2일
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' )

답변 (2개)

Massimo Zanetti
Massimo Zanetti 2016년 10월 7일
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'))
  댓글 수: 1
bsol
bsol 2016년 10월 14일
When I run your code, it still generates the plot without minor x ticks. The extra line does indeed make the ticks longer, but they still only appear when I resize the window. Let me know if you need more details to understand my issue.

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


Shubham
Shubham 2024년 9월 2일
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.

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by