Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have some data as follows (first and second columns) in the file mydata.d that 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 curve, 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 horizontally?

  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. I also tried TL 2011 with MetaPost 1.504.

Thanks a lot for your kind help...

share|improve this question

1 Answer 1

I would strongly suggest using pgfplots for such plots. Here is an example including data commenting, year handling thousands separations etc. :

\documentclass{article}
\usepackage{pgfplots}


\pgfplotstableread[skip first n = 4]{%
% Some TeX comment
Comment line
The number days that the doctor
will be kept away...
Comment end
year n
2008 98826   
2009 104925  
2010 140153  
2011 178414  
}\mytable


\begin{document}
\begin{tikzpicture}
    \begin{axis}[scaled ticks=false,
    xtick=data,
    xticklabel={\pgfmathprintnumber[fixed,1000 sep=]{\tick}},
    xticklabel style={rotate=90},
    yticklabel={\pgfmathprintnumber[int detect,fixed,1000 sep={\;}]{\tick}}
    ]
    \addplot table[x=year,y=n]{\mytable};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.