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

105 次查看(过去 30 天)
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