Clear Filters
Clear Filters

Why does the "alpha" function make the left and bottom borders of my figure disappear in MATLAB?

5 views (last 30 days)
The left and bottom borders of the axes disappear (although the ticks are displayed as expected - with 'box on') when I change the transparency of the plot.
Here is my code:
figure
area(1:10,1:10)
box on
alpha(0.2)
Why does that happen?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Oct 2013
This is due to a bug when using transparency in MATLAB. OpenGL does not render the borders correctly.
This issue occurs when a plot with some transparency has its edges overlapping with the edge of the figure.
Possible Workaround on Mac:
Increase the axes offset by a small value depending on the scale of your figure. For example:
figure
area(0:10,0:10)
box on
alpha(0.2)
set(gca,'xlim',[0 10.001])
set(gca,'ylim',[-0.001 10])
Possible workaround on Windows and Linux:
1. OpenGL is the renderer that MATLAB uses to handle transparency. By default, OpenGL runs in hardware acceleration mode to increase performance. Use OpenGL in software mode instead:
>> opengl software
Make sure to run this command before opening a new figure.
2. Once OpenGL is set to run in software mode, slightly increase the x-axis limit to make the right border reappear:
figure
area(1:10,1:10)
box on
alpha(0.2)
xlim([1 10.001])
This should also fix issues with the borders of the legend box.
  1 Comment
Adam Danz
Adam Danz on 30 Jul 2017
Edited: Adam Danz on 30 Jul 2017
I've been dealing with this bug on matlab vs 2014a for a few days and wanted to share my solution.
Slightly increasing the xlim/ylim partially solved this issue for me on some occasions but unfortunately each subplot needed different tiny offset values for the axes to fully appear.
My code was setting transparency (alpha) of objects in a plot and then setting axis limits. The axes disappeared after setting the axis limits. I changed the order of these commands so that axis limits were set before setting transparency. This fixed the problem for all of my subplots that were affected by this bug. Hope that helps.
Adam Danz

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2013b

Community Treasure Hunt

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

Start Hunting!