matplot: overlay

Overlay of two plots

Code:


var i,j, u=[], v=[], xq = [], yq = [];

// load the peaks sample data
peaks = matplot.peaks();

for (i=0; i < peaks.x.length-2; i++) {
  u[i] = [];
  v[i] = [];
  xq[i] = [];
  yq[i] = [];

  for (j=0; j < peaks.x[0].length-2; j++) {
    xq[i][j] = peaks.x[i+1][j+1]
    yq[i][j] = peaks.y[i+1][j+1]

    // compute geostrophic currents
    u[i][j] = -(peaks.z[i+1][j+2] - peaks.z[i+1][j]);
    v[i][j] = peaks.z[i+2][j+1] - peaks.z[i][j+1];
  }
}

// make a figure of size 700 x 500 pixels
//fig = new matplot.Figure("plot",700,500,{renderer: matplot.RasterCanvas});
fig = new matplot.Figure("plot",700,500);

// add axis to the figure
ax = fig.axes();


// pseudo color plot
ax.pcolor(peaks.x,peaks.y,peaks.z);

// arrow plot
ax.quiver(xq,yq,u,v,{scale: 0.1});

// add color-bar
ax.colorbar();

// draw everything
fig.draw();