help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pcolor with legend


From: Francesco Potorti`
Subject: pcolor with legend
Date: Fri, 25 Jul 2008 17:53:06 +0200

Apparently, pcolor has no legend :(

This is how I created a hand-made legend for pcolor.  May be of help to
others.

I used very similar code to create a legend for contourf, too, but I had
to tweak differently the "outerposition" numbers to get a good result.

================================================================
## Redefine pcolor so that last row and columns are not thrown away
function mypcolor(x,y,z)
  x0=3*x(1)-x(2);xe=3*x(end)-x(end-1);xm=x(1:end-1)+x(2:end);x=[x0;xm(:);xe]/2;
  y0=3*y(1)-y(2);ye=3*y(end)-y(end-1);ym=y(1:end-1)+y(2:end);y=[y0;ym(:);ye]/2;
  #x=[x(1);x(:)]+[x(:);x(end)]/2;
  #y=[y(1);y(:)]+[y(:);y(end)]/2;
  z=[z,z(:,end);z(end,:),z(end,end)];

  pcolor(x,y,z);
  shading("flat");
endfunction

################################################################
## Colour map (1dB per colour)
subplot(1,2,1);
mypcolor(x,y,z);
colormap(jet(dbmax-dbmin));
caxis([dbmin dbmax]);

## Legend: a vertical bar using the same colour map and axes limits
subplot(1,2,2);
s=linspace(dbmin,dbmax,1000)';
pcolor([dbmin dbmax]/10,s,[s s]);
#set(gca,"yaxislocation","right"); # Y axis disappears in Octave 3.0:(
set(gca,"dataaspectratio",[1 1 1]);
axis("ticy");
shading("flat");
colormap(jet(dbmax-dbmin));
caxis([dbmin dbmax]);

## Reposition and scale the two graphs
set(get(gcf).children(1),"outerposition",[-0.1,-0.1,1.1,1.2])
set(get(gcf).children(2),"outerposition",[0.75,-0.1,0.4,1.2])
#print("-Pcolore","-color","-landscape")

-- 
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: address@hidden
(entrance 20, 1st floor, room C71)     Web:   http://fly.isti.cnr.it/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]