altmany / export_fig

A MATLAB toolbox for exporting publication quality figures
BSD 3-Clause "New" or "Revised" License
1.27k stars 365 forks source link

yyaxis right gives only white space in .eps file #380

Closed paulbarron85 closed 6 months ago

paulbarron85 commented 1 year ago

I'm trying to create a figure where I use yyaxis right and yyaxis left. When I try to export figure there's nothing in the image, just white space. If I comment out yyaxis left and yyaxis right then export_fig works correctly.

figure(); hold on;
leg = {numOfSelectedFeatures};
secondaryAxisArrayIndex = [2 3];
legendAxis = [];
for i = 1:numOfSelectedFeatures
    if ismember(i, secondaryAxisArrayIndex)
        yyaxis right;
        ha = plotyy(selectedFeatureData{i});
        legendAxis = [legendAxis ha];
    else
        yyaxis left;
        hb = plot(selectedFeatureData{i});
        legendAxis = [legendAxis hb];
    end
    leg{i} = char(FeatureNames(selectedFeatureArray(i)));
end
hold off;
lgnd = legend(legendAxis, leg); 
set(lgnd,'color','none');
if (saveFigures == true)
    filename = "..\Latex Document\figures\Models_Signal" + selectedSignal + "Feature" + selectedFeature;
    export_fig(filename, '-eps');
end
altmany commented 6 months ago

I cannot reproduce the problem using the code snippet below, which is supposedly equivalent to your code (the code that you uploaded is not runnable as-is):

figure; hold on;
yyaxis right; h1=plot(1:5); 
yyaxis left; h2=plot(20:40); 
hold off; 
legend([h1,h2],'right','left');
drawnow; pause(1);  % render the figure
export_fig test.eps; winopen test.eps

image

Perhaps the problem is that in your yyaxis right code branch you are using plotyy instead of plot. In this case it's not a problem of export_fig but a bug in your code.

If the problem persists, then please reopen this issue and upload a reproducible runnable code snippet.