Amelio Vazquez-Reina
Amelio Vazquez-Reina

Reputation: 96458

Black lines missing in the box holding the axes of a MATLAB plot

When plotting on a figure in MATLAB, I have noticed that parts of the black box that holds the axes are missing (the left and bottom one):

              enter image description here

I have tried issuing:

box off
box on

commands with no success. Do you know what I can do to get the corresponding black lines on the axes?

Note:

I am using the OpenGL renderer:

set(0,'DefaultFigureRenderer','opengl');

Upvotes: 7

Views: 11260

Answers (4)

OGCJN
OGCJN

Reputation: 393

Being a perfectionist this bug bothered me for years! This is what seems to work, MATLAB R2013a:

  1. I have OpenGL off (gives all kind of weird behavior): set(0,'DefaultFigureRenderer','zbuffer')
  2. I add a box just before I plot something and right after I finish plotting:

    axes(handles.MyAxes);
    
    cla;
    
    hold off;  
    box on;
    hold on;
    
    % Do your plotting...
    % scatter(...);
    % plot(...);
    % ...
    
    box on;
    
  3. I also noticed that if the first command is plot then the bug may still be present. In this case I plot just a single point using scatter with white color (makes it invisible) and then use plot. That is, scatter(x(1),y(1),1,'MarkerEdgeColor','w','MarkerFaceColor','w') and then plot(x,y,...).

My answer in fact refers to missing box lines when plotting in a GUIDE figure. I never had this issue when using a regular figure() and then plot(...) commands.

Hope it helps!

Upvotes: 0

Will Cousins
Will Cousins

Reputation: 11

Use the following line of code to make the black lines appear

set(gca,'Layer','top')

Upvotes: 1

Dirk
Dirk

Reputation: 21

Try increasing the line width of the axes a bit:

set(gca, 'LineWidth', 1.2)

Also, switching from hardware (default) to software rendering may solve the problem:

opengl software

However, there may be drawbacks. Increasing the line width, e.g., changes all axes lines, including ticks.

Upvotes: 2

Related Questions