[metapost] graphing problems in metapost

Yogeshwarsing Calleecharan yogeshwarsing.calleecharan at ltu.se
Fri Nov 11 12:32:08 CET 2011


Hi,
     I have some data as follows (first and second columns) in the file 
mydata.d which I want to graph:

8   98826   year 2008
9   104925  year 2009
10  140153  year 2010
11  178414  year 2011

As we have big numbers in the second numbers, I have used the macro 
sarith. Here's my metapost code for the plot:

input graph
input sarith
beginfig(1);
draw begingraph(8cm,5cm);
setrange(8,whatever,12,whatever);
gdraw "mydata.d" withpen pencircle scaled 1.5pt;;
gdraw "mydata.d" plot btex $\bullet$ etex;
autogrid(otick.bot,);
gdotlabel.lrt(btex $98\;826$ etex, 8,"98826");
gdotlabel.lrt(btex $104\;925$ etex, 9,"104925");
gdotlabel.lrt(btex $140\;153$ etex, 10,"140153");
gdotlabel.lrt(btex $178\;414$ etex, 11,"178414");
endgraph;
endfig;
end

So I am plotting the first two columns, taking away the y-axis tickmarks 
and labels and also writing the y-value at each coordinate in the plot. 
I have the following questions:

1. I wanted to show the year i.e. 2008 to 2010 but metapost just shows 
2010 along the x-axis and this is why I have chosen the numbers 8 to 10 
instead. Why is that?

2. If you plot the curves, you would see two dots at each coordinate 
where the corresponding y-value is written. Why is this happening? This 
occurs even if I take away
      the line gdraw "mydata.d" plot btex $\bullet$ etex. In the 
gdotlabel lines, I have to include the numbers in the second column in 
quotes e.g. "98826". Is this causing a
     problem for metapost to be accurate at such a large numbers and 
hence the appearance of two dots?

3. If from 1 we can show the year 2008, 2009, 2010 and 2011 well, then 
how can we display them but rotated say 90 degree anticlockwise so that 
the labels do not take
     too much space horizintally?

4. If I ask metapost to display the y values on the y-axis, well it will 
write in exponential form instead of pure decimal form like 100000, 
150000 etc. How to achieve this?

5. I understand that metapost ignores columns other than the two columns 
and this is useful to write comments pertaining to that line e.g. year 
2008 on the first line.
     However if I would like to add a global comment to the whole file 
such as "Number of apples I ate in each year", then I cannot do this in 
the beginning of the file.
     I presume that we can do it at the end of the file, but how? I have 
tried leaving blank spaces and starting the comment line with a % sign 
but this doesn't work.


I am using TeXLive 2010 under Win XP with  MetaPost, version 1.211.


Thanks a lot for your kind help...

Best Regards,
Y.Calleecharan


More information about the metapost mailing list