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

248 Ansichten (letzte 30 Tage)
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 Kommentare
Leo
Leo am 31 Jan. 2017
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 am 12 Jan. 2018
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);

Melden Sie sich an, um zu kommentieren.

Antworten (4)

Michelle Wu
Michelle Wu am 31 Jan. 2017
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 am 9 Feb. 2020
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 am 11 Jan. 2018
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 am 27 Jun. 2018
Your solution worked for me as well. Thanks

Community Treasure Hunt

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

Start Hunting!

Translated by