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

9 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 18 Okt. 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 Kommentar
Adam Danz
Adam Danz am 30 Jul. 2017
Bearbeitet: Adam Danz am 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Produkte


Version

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by