[metapost] Bargraphs with metapost

Geoff Russell geoffrey.russell at gmail.com
Sun Oct 29 07:39:19 CET 2006


Regarding the metapost graph macros,

I'm building bargraphs with metapost and have a problem positioning
the labels for the bars. I need the y value in the graph space, but the x
value in the "outside"
coordinates.  I've crawled around the macros, but they are too deep for me!

Cheers,
Geoff Russell.

------------ Sample data file: totalwater.d
1       3 Beef
2       5 Dairy
3      13 Rice
4      16 Cotton

-------------- Metapost code

prologues:=1; warningcheck:=0;
input string
input sarith
input graph
numeric barwidth; barwidth:=0.4;
color lightc;
lightc:=5/6[red,white];

vardef dobar (expr y,w,l) =
     save p; pair p; p:=(0,Scvnum s1-0.2);
     gfill p--(p+(w,0))--(p+(w,barwidth))--
               (p+(0,barwidth))--cycle withcolor c[1];
     % I NEED SOMETHING HERE TO POSITION label l
enddef;

color c[];
c[1]:=blue; c[2]:=lightc; c[3]:=1/2[blue,red];

% Total Water Use
beginfig(1);
     draw begingraph(2in,1.4in);
     gdata("totalwater.d",s,
          dobar (Scvnum s1,Scvnum s2,s3);
     );
     autogrid(otick.bot,);
     glabel.top(btex \vbox{\hbox{Total Water Use --- '000 gigalitres}}
etex,OUT);
     endgraph;
endfig;
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://tug.org/pipermail/metapost/attachments/20061029/6a3158b9/attachment.html 


More information about the metapost mailing list