2

I would like to put contour plots of two datasets on the same axes with the same colorbar. The X and Y ranges of the data do not overlap but are physically adjacent.

Here's a simplified example of two such contourf plots which I'd like to combine on the same axes:

   %generate 1st sample dataset
   [x1,y1]=meshgrid(-3:3);
   v1=peaks(x1,y1)

   %generate 2nd sample dataset & move it so it is physically adjacent to 
   %1st dataset
   [x2,y2]=meshgrid(-4:4);
   v2=peaks(x2,y2)
   x2=8+x2;

   figure(1)
   contourf(x1,y1,v1)
   colormap(jet)
   colorbar('EastOutside')
   xlabel('x (mm)')
   ylabel('y (mm)')

   figure(2)
   contourf(x2,y2,v2)
   colormap(jet)
   colorbar('EastOutside')
   xlabel('x (mm)')
   ylabel('y (mm)')

This produces the following plots

enter image description here enter image description here

I tried to put the two sample datasets on the same axes using the following:

    figure(3)
    contourf(x1,y1,v1)
    colormap(jet)
    hold on

   contourf(x2,y2,v2)
   colormap(jet)
   hold off

Using the typical "hold on" didn't work... suggestions??

Deve
  • 4,528
  • 2
  • 24
  • 27
campel
  • 21
  • 1

1 Answers1

0

The second contour plot is invisible as the x axis limits are too small. Add the following commands to your script after hold off

xlim([-3 12]);
ylim([-4 4]);

This will produce the following plot

Plot

Deve
  • 4,528
  • 2
  • 24
  • 27