Problem with markers & dashed lines in figures containing both plot and fill

조회 수: 4 (최근 30일)
The legend gets somewhat distorted in plots that contain both lines and fill objects. For example, compare the legend produced by this:
figure;
plot(linspace(0,pi,25),cos(linspace(0,pi,25)),'s--','LineWidth',2,'MarkerFaceColor','b');
hold on;
plot([0 pi],[0.5 0.5],'-or','LineWidth',2,'MarkerFaceColor','r');
h = fill([0 pi pi 0],[1 1 -1 -1],'g','FaceAlpha',0.15);
hA = get(h,'Annotation');
hA.LegendInformation.IconDisplayStyle = 'off';
legend({'Cosine','Constant'},'interpreter','latex');
with the output when we don't have the fill object:
figure;
plot(linspace(0,pi,25),cos(linspace(0,pi,25)),'s--','LineWidth',2,'MarkerFaceColor','b');
hold on;
plot([0 pi],[0.5 0.5],'-or','LineWidth',2,'MarkerFaceColor','r');
legend({'Cosine','Constant'},'interpreter','latex');
Any solution would be appreciated.
EDIT: At first, I didn't realize that the markers on the plot lines also get distorted as well. So I guess, this whole problem is caused by fill.

채택된 답변

Matt Fig
Matt Fig 2012년 8월 23일
This is a problem with the opengl renderer. When you have a transparency, you are using opengl, and it can be buggy. To see the difference, click on that figure then:
set(gcf,'render','painters')
Notice the legend looks fine but your transparency has gone away. I am not sure if there is a fix for this.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by