Search code examples
matlabgraphplotstacked-area-chart

MATLAB: Stacking .figs


I'm currently working on a study about fuel consumption. I have multiple .fig files that shows the trend of fuel consumption in L/100 Km versus Time. I have multiple cases showing the behavior of the plot under different conditions, and I wan't to show the differences between them. An example of the plot is shown below:

enter image description here

Is there anyway to stack plots from different .fig files in 1 .fig file?


Solution

  • Ideally, you'd want to generate those different plots using subplot.

    Your exact question has been answered by ZiV in the mathworks forums:

    One way to do this is to extract xdata and ydata from existing figures, then re-plot these data in a new figure window as desired. For example,

    open('gugu.fig');
    h_gugu=get(gca,'Children');
    x_gugu=get(h_gugu,'XData');
    y_gugu=get(h_gugu,'YData');
    
    open('lulu.fig');
    h_lulu=get(gca,'Children');
    x_lulu=get(h_lulu,'XData');
    y_lulu=get(h_lulu,'YData');
    
    figure
    subplot(121)
    plot(x_gugu,y_gugu);
    subplot(122)
    plot(x_lulu,y_lulu)
    saveas(gcf,'gugululu','fig')