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 would like to know how to use PSTricks to read and plot data from a text data file e.g.

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

And three further questions:

  1. Can comments like "year 2008" added after the two first columns be ignored in PSTricks?

  2. And is it possible to add a general comment and headings to the data file while still make it possible for PSTricks to read the data file?

  3. Is PSTricks suitable to plot large amount of data? I do not know how large is large but say more than 100 points. I typically use Matlab for my plots but I am considering other options that are closer to LaTeX.

share|improve this question
    
Would a PGFplots solution be interesting as well? –  Torbjørn T. Nov 23 '11 at 9:21
    
I see from the PGFplot manual that this pacakge has much to offer. Does it work with TeXLive also? Yes you are welcome to provide a PGFplot solution here but I cannot guarantee that I will accept your solution if others will come up with PStricks-based solutions here. –  yCalleecharan Nov 23 '11 at 9:28
    
It's a standard part of TeXLive now. Check out my recent answer with an introduction to pgfplots, including how to use a file. –  qubyte Nov 23 '11 at 9:45
1  
You may need to index by column number if there are no column headers. Do this like \addplot table[x index=0,y index=1] {datafile.dat}; –  qubyte Nov 23 '11 at 9:53
1  
Look at this page of the PSTricks website. They mention an example with 1000 data records. The documentation for pst-plots and pst-add will help. You can find it on CTAN. –  DJP Nov 24 '11 at 2:32

2 Answers 2

up vote 2 down vote accepted

Since nobody has attempted a solution I'll mention: 1. According to the PST-plot documentation (page 6), comments can be added after the first 2 columns but you'll need to put a percent sign before it. 2. Headers can be added; to ignore them you use the ignoreLines command (page 58) so if your header is 20 lines, then ignoreLines=20 is used. Finally, the PSTrick page I commented on above and the documentation from PST-plot (page 59-60) mentions an example with 1000 data records. Since you indicate you are using page 6 of the documentation says the \dataplot command is for lists of data created by other programs. Maybe you don't need to consider other options. I haven't used this package much; I played around and got this (light comments included):

\documentclass[11pt]{article}
\usepackage{pstricks,pst-plot}
\pagestyle{empty}
\begin{document}
\readdata[ignoreLines=1]{\mydata}{ExData} %ignores 1 line
\psset{xAxisLabel=My x-Axis,yAxisLabel=My y-Axis, xAxisLabelPos={c,-3},yAxisLabelPos={-2,c}}
% the position of your axes labels can be adjusted by changing, for example xAxisLabelPos={c,-2}
\pstScalePoints(1,.00001){}{} %the y values have been multiplied by 1/10^5  so they'll show
\begin{psgraph}[axesstyle=frame,Dy=1,ylabelFactor=\cdot 10^5,Dx=1,ticksize=5pt 0](1,0)(11,7){10cm}{8cm}%the labels have been adjusted to reflect the 1/10^5
%the (1,0) starts the first record on the y-axis 
\listplot[linecolor=red, linewidth=1pt,showpoints=true]{\mydata}
\end{psgraph}
\end{document}

The data file (ExData) has this as its contents:

A useless header
1   234611  %year 2000
2   645511  %year 2001
3  345311  
4  235411 
5   342526  
6   134525 
7  145153  
8   98826   
9   104925 
10  140153  
11  178414

Output above enter image description here

share|improve this answer

The number of data records is not limited ...

\listfiles
\documentclass{article}
\usepackage{pst-plot,filecontents}

\begin{filecontents*}{test.data}
8   98826   year 2008
9   104925  year 2009
10  140153  year 2010
11  178414  year 2011 
\end{filecontents*}

\begin{document}
\readdata{\mydata}{test.data}
\pstVerb{/year {} def }
\pstScalePoints(1,1){}{1.e4 div}

\psset{xAxisLabel=My x-Axis,yAxisLabel=My y-Axis, xAxisLabelPos={c,-1.5},yAxisLabelPos={-0.5,c}}
\begin{psgraph}[axesstyle=frame,Dy=2,Oy=8,Ox=8,ylabelFactor=\cdot 10^4,ticksize=5pt 0](8,8)(11,20){10cm}{8cm}
\listplot[linecolor=red, linewidth=2pt,showpoints,dotstyle=square,
  plotNoMax=2,plotNo=1]{\mydata}
\end{psgraph}

\end{document}

enter image description here

share|improve this answer
    
Where is the \pstVerb command documented? There's no mention of it in the pst-plot documentation. –  Alan Munn Nov 25 '11 at 18:21
    
I chose DJP's answer as it gives the input from an external file as required by the question but otherwise your two codes are pretty much alike and helpful. 1 vote up. –  yCalleecharan Nov 28 '11 at 7:00
1  
@yCalleecharan: All data is read from an external file ... –  Herbert Nov 28 '11 at 7:17
    
@ Herbert. Yes now I can see that you have defined your data before \begin{document} and that you are reading from a file. –  yCalleecharan Nov 28 '11 at 11:02

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.