Some legend properties are reset to default when printing figure

13 ビュー (過去 30 日間)
Rodeo Ryan
Rodeo Ryan 2014 年 3 月 17 日
コメント済み: Dan Fries 2020 年 5 月 22 日
I am printing a figure into the -depsc format using the print() command. The figure has two subplots, with a legend in the upper plot. An example of the code I'm using to generate the plot is below:
figure1=figure;
set(gcf,'Position',[100 100 1100 650])
set(gcf,'PaperPositionMode','auto','DefaultAxesFontname','TimesNewRoman')
subplot1=subplot(2,1,1,'Parent',figure1,'FontSize',12);
hold(subplot1,'all');
box(subplot1,'off');
plot(x1,y1,'Parent',subplot1,'Color','k','LineStyle','-','DisplayName','Field')
plot(x2,y2,'Parent',subplot1,'Color','k','LineStyle','--','DisplayName','Model')
subplot2=subplot(2,1,2,'Parent',figure1,'FontSize',12);
hold(subplot2,'all');
box(subplot2,'off');
plot(x3,y3,'Parent',subplot2,'Color','k','LineStyle','-')
plot(x4,y4,'Parent',subplot2,'Color','k','LineStyle','--')
legend1=legend(subplot1,'show');
set(legend1,'Location','NorthWest','EdgeColor',[1 1 1],'Color',[0.5 0.5 0.5]);
Then, to print the figure in color eps format, I use the following command:
print(figure1,'-depsc','-r300','Figure1.eps');
The problem is that, even though I specify 'EdgeColor' [1 1 1] and 'Color' [0.5 0.5 0.5] in the Legend properties, these are not honored when printing. The EdgeColor in the printed file is black and the background Color of the legend is reset to white. But for some reason, the property setting the Location to NorthWest is honored and NOT reset to the default, NorthEast.
I thought maybe it was only honoring the first property for some reason, so I deleted the Location property, making the EdgeColor property the first one in the list. However, the EdgeColor in the printed .eps file was still black...
Anybody know the solution to this problem? Is this an unnoticed/unresolved bug?? I am using Matlab_R2013a, in case that makes any difference in solving this problem.
Thanks!
  3 件のコメント
Jan Vábek
Jan Vábek 2020 年 4 月 7 日
Hello,
any progress on this issue? It seems to be persistent even in R2019a. I'm trying to save a png file with a different text color in the legend. I've a correct output on the screen and also when I use "File" -> "Save As..." However, the color is reset to default using the print command.
Dan Fries
Dan Fries 2020 年 5 月 22 日
I am having the same issue. Is there any way to work around this or fix it?

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 5 月 22 日
I think you seeing the effect of InvertHardcopy figure property; https://www.mathworks.com/help/matlab/ref/matlab.ui.figure-properties.html#buiwuyk-1-InvertHardcopy
  1 件のコメント
Dan Fries
Dan Fries 2020 年 5 月 22 日
Thanks for looking into this. Unfortunately, even setting InvertHardcopy to 'off' does not help. The rough code I am using is below. The moment "print" is called the linestyle oin the legend is reverted to default, i.e. from '-' to '--', but I would like it to be '-' in the legend.
Any ideas?
figure
fig1 = gcf;
fig1.Units = 'inches';
size_width = 8;
size_height = 4;
fig1.Position = [5 0 size_width size_height];
hold on
a = plot(x1,y1,'--');
b = plot(x2,y2,'--');
c = plot(x3,y3,'--');
d = plot(x4,y4,'--');
[hLgd, oLgd] = legend([a b c d],{'X1' 'X2' 'X3' 'X4'},'Location','Southeast');
lineh = findobj(oLgd,'type','line');
set(lineh,'LineStyle','-')
cd(saveDir)
figure(fig1)
set(gcf,'InvertHardcopy','off')
fig1.PaperUnits = 'inches';
fig1.PaperPosition = [0 0 size_width size_height];
fig1.PaperPositionMode = 'manual';
fig1.PaperSize = [size_width size_height];
print(fig1,'FigureTest','-depsc','-r300')
print(fig1,'FigureTest','-dpdf','-r300')
print(fig1,'FigureTest','-dpng','-r300')
savefig('FigureTest')

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by