Re: [ROOT] print numbers in scatter plots.

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Jul 04 2001 - 18:49:01 MEST


Hi Tommaso,

There are better and simple procedures to encode an integer in a string.
A conservative and general procedure is the following: Instead of the lines:

      std::ostringstream buffer;
      buffer << index;
      string s = buffer.str();
      char *c = new char[s.length()+1];
      strcpy(c, s.c_str());
      tex = new TLatex(tr.x(),tr.y(),c);

do:
      char c[4];
      sprintf(c,"%d",index);
      tex = new TLatex(tr.x(),tr.y(),c);

Rene Brun

Tommaso Chiarusi wrote:
> 
> Dear Root Users my problem is the following:
> I have N points that I want to plot (let's say I know their X and Y).
> I have also an integer index "index" that is associated to each point I
> plot,
> and which increases of one unit its value after the point has been plot.
> Let's say:
> 
> index = 0;
> 
> for (int j=0;J<N;j++)
> {
>         Plot(Point);
>         index++;
> }
> 
> My whish woulkd be plotting the value of i by the point in the scatter
> plot, as in the following naive picture:
> 
> Y
> ^ 2
> | *  3
> |    *
> | 1
> | *
>  -------->X
> 
> One usually uses the TLatex class for drawning text onto graphics.
> The problem is that the object
> 
> tex = new TLatex(X,Y,c)
> 
> wants c  to be of type char*
> 
> So I use the following procedure:
> I included the two libs:
> #include <sstream>
> #include <string>
> 
> then
> 
>       std::ostringstream buffer;
>       buffer << index;
>       string s = buffer.str();
>       char *c = new char[s.length()+1];
>       strcpy(c, s.c_str());
>       tex = new TLatex(tr.x(),tr.y(),c);
>       tex->SetTextSize(0.02);
>       tex->SetTextColor(1);
>       tex->SetLineWidth(.5);
>       tex->Draw();
>       index++;
> 
> I finally got printed the numbers, but together with special characters
> (trash!!!) as for example:
> 
> Y
> ^ 2 @h'@
> | *  3 @yyyyyy@@@
> |    *
> | 1 @@yPPPy@@@@
> | *
>  -------->X
> 
> Well I don't know how to get rid of such dirty characters, which
> originate, I presume, from the passage when buffering or when
> string-copying.
> 
> Thank you very much for your attention, and for a halp.
> 
> Tommaso
> 
>



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:51 MET