How do I remove the border lines surrounding an axes?

조회 수: 664 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2009년 6월 27일
댓글: Matt 2024년 2월 1일
When I make a simple plot, I would like to turn off the border around the axes. However,
box off
removes only part of the border. I have removed all of the tick marks and labels, but there are still 2 border lines present. Is there a way to remove them?
You can reproduce the issue as follows:
hAx = axes;
set(hAx, 'box','off','XTickLabel',[],'XTick',[],'YTickLabel',[],'YTick',[])

채택된 답변

MathWorks Support Team
MathWorks Support Team 2024년 2월 1일
편집: MathWorks Support Team 2024년 2월 1일
The ability to remove all of the border lines surrounding an axes is available in MATLAB R2016a and onward. For example:
hF = figure();
hA = axes(hF);
plot(1:10);
set(hA, 'XTick', [], 'XTickLabel', []);
set(hA, 'YTick', [], 'YTickLabel', []);
set(get(hA, 'XAxis'), 'Visible', 'off');
set(get(hA, 'YAxis'), 'Visible', 'off');
For MATLAB releases prior to R2016a, depending on your application, you might be able to use one of the following options as a workaround:
1. You can change the 'XColor' and 'YColor' properties of the axes to match the color of the background of the figure. This makes the axis lines invisible against the figure background. You must also eliminate the tick marks and minor tick marks that extend into the axes. The easiest way to do this is to change their direction such that they point outward, as opposed to inward. For example:
hFig = figure;
plot(1:10)
color = get(hFig,'Color');
set(gca,'XColor',color,'YColor',color,'TickDir','out')
2. Make the axes invisible by setting the axes 'Visible' property to 'off'. For example:
plot(1:10)
set(gca,'Visible','off')

추가 답변 (1개)

Royi Avital
Royi Avital 2024년 1월 12일
In newer MATLAB versions this can be done using the XAxis and YAxis sub objectes:
hF = figure();
hA = axes(hF);
set(hA, 'XTick', [], 'XTickLabel', []);
set(hA, 'YTick', [], 'YTickLabel', []);
set(get(hA, 'XAxis'), 'Visible', 'off');
set(get(hA, 'YAxis'), 'Visible', 'off');
This will result in a clean axes.
  댓글 수: 1
Matt
Matt 2024년 2월 1일
Hi Royi, thank you for bringing this to our attention. I have updated the article to incorporate this work around.

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

카테고리

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

제품


릴리스

R2006a

Community Treasure Hunt

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

Start Hunting!

Translated by