Search code examples
matlabplotfigure

Overlaying / Plotting on top of an existing plot in MATLAB


I have a heat map of values generated by "pcolor" in MATLAB. I would like to plot a line plot on top of that.

I haven't found a proper solution in any measure yet.

The following code generates a "heat map" sort of output

 hc = pcolor(middle_long, middle_height, middle_no2);
 set(hc, 'Edgecolor', 'none');
 c = colorbar;
 caxis([0 0.015]);
 axis([min(middle_long(:,1)) max(middle_long(:,1)) 0 1000])

The following code generates a line plot

 plot(longflag, hflag)

The following are figures of the individual plot types that I would like to join, with an "example" of the final product I'd like listed afterwards:

enter image description here

enter image description here

enter image description here


Solution

  • Try something like this. Note the hold on part, which prevents plot from deleting the image produced by pcolor:

    pcolor(rand(10))
    colormap bone
    axis xy
    hold on
    plot([1 10], [10 1], 'r')
    

    enter image description here