Counting points from csv file pgfplots

I am importing data from a .csv file to obtain a scatter plot, here's the MWE:

\documentclass{article} \usepackage{pgfplots}  \pgfplotsset{     jitter/.style={         x filter/.code={\pgfmathparse{\pgfmathresult+rnd*#1}},         y filter/.code={\pgfmathparse{\pgfmathresult+rnd*#1*0.1}}     },     jitter/.default=0.1 }  \begin{document}  %%% Victory Opening vs Victory Race \begin{figure}     \begin{tikzpicture}         \begin{axis}[width=15cm,                     axis background/.style={fill=blue!10},                     xlabel={Victory Opening},                     ylabel={Victory Race},                     legend entries={Winners, Losers},                     legend style={nodes=right},                     legend pos= north east,                     ]          \addplot +[only marks,mark=o] table [col sep=comma,x=VictoryOpening,y=VictoryRace]{MapsFullNumerical.csv};         \addplot +[only marks,red,mark=x] table [col sep=comma,x=LossOpening,y=LossRace]{MapsFullNumerical.csv};         \end{axis}      \end{tikzpicture}     \caption{Victory Opening vs Victory Race} \end{figure} \end{document} 

what I would like to do is count the number of points for each cluster. Here the first two lines of the .csv file:

NomeRep,VictoryOpening,VictoryRace,LossOpening,LossRace,numRegioni,numBasi,numStart,hopMedio,numChoke,numArchi,FlussoMedio,FlussoMedioBasi,FlussoMedioStarting,percPosStratReg,percPosStratBas,percPosStratStart,perimetroMedio,perimetroMedioBasi,perimetroMedioStarting,areaMedia,areaMediaBasi,areaMediaStarting,chokeMedio,chokeMedioBasi,chokeMedioStarting,perc chokePerimetro,perc chokePerimetroBasi,perc chokePerimetroStarting,mediaMinBasi,mediaMinStart,mediaGasBasi,mediaGasStart,blocchiMinBase,blocchiMinStarting,distanzaRegTerra,percraggRegTerra,distanzaRegTerra95,distanzaBasiTerra,percraggBasiTerra,distanzaBasiTerra95,distanzaStartTerra,percraggStartTerra,distanzaAriaBasi,distanzaAriaStartPoints,numRegNonRaggiungibili,gradoMedio,HR Start-Reg,HR Start-Base,HR Base-Reg,Min/Gas Ratio Basi,Min/Gas Ratio Start  1,5,3,8,1,21,16,8,3.3,23,22,315,323,299,28,30,50,3689,3300,3756,552668,442894,557594,1938,1259,924,52,43,24,4615,5000,12923,12000,8,8,2988,81,2855,3156,100,3024,4352,100,2263,2808,0,2,1.72,1.61,1.03,0.36,0.42  

And here's the image obtained so far: Counting points from csv file pgfplots

Replay

Assuming all your .csv files have the same structure, you could do the following, using the xstring package. My \countpointsfromcsv counts the number of commas in the first line of your .csv file, adds one to that number, and prints the result. It prints "52" when applied to the csv data your provided.

\documentclass{article}

\usepackage{xstring}
\usepackage{filecontents}

\begin{filecontents*}{MapsFullNumerical.csv}
NomeRep,VictoryOpening,VictoryRace,LossOpening,LossRace,numRegioni,numBasi,numStart,hopMedio,numChoke,numArchi,FlussoMedio,FlussoMedioBasi,FlussoMedioStarting,percPosStratReg,percPosStratBas,percPosStratStart,perimetroMedio,perimetroMedioBasi,perimetroMedioStarting,areaMedia,areaMediaBasi,areaMediaStarting,chokeMedio,chokeMedioBasi,chokeMedioStarting,percchokePerimetro,perc chokePerimetroBasi,percchokePerimetroStarting,mediaMinBasi,mediaMinStart,mediaGasBasi,mediaGasStart,blocchiMinBase,blocchiMinStarting,distanzaRegTerra,percraggRegTerra,distanzaRegTerra95,distanzaBasiTerra,percraggBasiTerra,distanzaBasiTerra95,distanzaStartTerra,percraggStartTerra,distanzaAriaBasi,distanzaAriaStartPoints,numRegNonRaggiungibili,gradoMedio,HRStart-Reg,HR Start-Base,HR Base-Reg,Min/Gas Ratio Basi,Min/Gas Ratio Start

1,5,3,8,1,21,16,8,3.3,23,22,315,323,299,28,30,50,3689,3300,3756,552668,442894,557594,1938,1259,924,52,43,24,4615,5000,12923,12000,8,8,2988,81,2855,3156,100,3024,4352,100,2263,2808,0,2,1.72,1.61,1.03,0.36,0.42
\end{filecontents*}

\newread\myread%

\newcommand\countpointsfromcsv[1]{%
    \openin\myread=#1%
    \read\myread to \mycsvlist%
    \StrCount{\mycsvlist}{,}[\numberminusone]%
    \the\expandafter\numexpr\numberminusone+1\relax%
    \closein\myread%
}

\begin{document}
\countpointsfromcsv{MapsFullNumerical.csv}
\end{document}

Reference (for \read): http://tex.stackexchange.com/a/101936/21891

Category: tikz pgf Time: 2012-06-09 Views: 1

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.257 (s). 12 q(s)