Is there a way to remove the ticks on the right and upper side when the box is on ?

조회 수: 261 (최근 30일)
Leo
Leo 2017년 1월 28일
댓글: Dyuman Joshi 2023년 12월 26일
Hello,
When the parameter "box on" is activated, I want to get the box around the plot without the ticks on the right and upper axes. I have the ticks in the outer direction and having them on the right and top side look really odd...
I tried creating another empty axis on top that cover the right and upper part but the scaling is really suboptimal when saving the figure:
box off
ax1 = gca;
ax2 = axes('Position', get(ax1, 'Position'), 'FontSize', 10,...
'Color','None','XColor','k','YColor','k', 'LineWidth', 1,...
'XAxisLocation','top', 'XTick', [],...
'YAxisLocation','right', 'YTick', []);
linkaxes([ax1, ax2])
Cheers,
Leo
  댓글 수: 3
Leo
Leo 2017년 1월 31일
The problem is that the window is rescaled when the figure is saved as pdf. If you try to change the size of the window you will see that the axis do not meet at the edges.
My solution is to open the window with the same size as the exported plot.
set(gcf, 'Position', [0 0 width height])
Tiago Dias
Tiago Dias 2018년 1월 12일
Hello, i want to my plot have the axes with a width of 2, and the middle lines (grid) to have a width of 0.5 for example is that possible?
because when I do hte code below, it changes both the 4 axis bottom top left right and also the middle lines.
bon on
ax = gca;
set(ax,'linewidth',1.5);

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

답변 (4개)

Michelle Wu
Michelle Wu 2017년 1월 31일
Unfortunately, as of R2016b, it is not possible to configure the top and bottom as well as left and right ticks separately. "XTick" and "YTick" are axes properties, which only allow the ticks to be configured together. The workaround that you have in place right now seems to be the best way to get around this issue.
An enhancement request has been submitted to the development team at MathWorks.

SARA OUANES
SARA OUANES 2020년 2월 9일
Dear Leo,
My answer comes late but I hope it would help others in the future.
To solve such a problem, you can keep Box in 'off' position and create two lines (one horizontal and the other vertical) to outline your plot box at limits.
figure
plot(1:11,1:11)
box off
xlim([0 14])
ylim([0 14])
line([0 14],[14 14],'Color','k')
line([14 14],[0 14],'Color','k')

Amin Rajabi
Amin Rajabi 2018년 1월 11일
Your code works very well, and thanks for that as I had the same problem and your code saved me a lot of time.

Hari Prasanth
Hari Prasanth 2018년 6월 27일
Your solution worked for me as well. Thanks

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by