Why does legend patch turn black when using saveas?

조회 수: 3 (최근 30일)
Patrik Ek
Patrik Ek 2014년 10월 23일
편집: Patrik Ek 2014년 10월 23일
Hi, I have a problem with the function saveas in matlab. The problem appears when I create a legend for more than one graph (eg 2 line graphs) in an image and then uses saveas on the figure. The problem is that when I try to use saveas (or publish, which uses saveas) on the image and the legend patch (the object named rectangle) is set to white, the patch turns black in the image (for me a .png image).
Since I wanted to set the background of the legend object to semi-transparent I had to remove the box and this causes some problems. The details will be seen in the example code. I am not sure whether there is a problem for all types of images, but I know it is at least a problem for .png images.
Have anyone seen this problem before and is it a known fix or workaround for it?
Example code:
publish('testScript');
function testScript()
figure;
plot(1:10,2:11,1:10,1:10,'r','LineW',2);
legend({'leg1','leg2'});
setLegendAlpha(0.9);
function setLegendAlpha( alphaValue )
hleg=findall(gcf,'tag','legend');
set(hleg,'box','off');
ch=findall(hleg,'type','axes');
ah=annotation('rectangle',get(ch,'position'));
set(ah,'facecolor','w','facealpha',alphaValue);
uistack(hleg,'top');
I am not sure if this problem is due to some error in the code in the function setLegendAlpha or if it is a bug. Also, if someone knows a workaround that does not cause the legend background to turn black when saving with saveas I would be happy. I can add that this problem cannot be seen in the figure and if I save it using file->save this problem is not seen either.
Matlab 2014a, windows 7
  댓글 수: 1
Patrik Ek
Patrik Ek 2014년 10월 23일
편집: Patrik Ek 2014년 10월 23일
If this is a known bug or is unsupported I would also appreciate a comment or so. In both cases it would be worth sending a bug report on and also add that this is something that would be valuable in future releases. I think that it is a usual that legends become to long or to large.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by