RE: TGraph drawing options

From: Anton Fokin (fokin@tsl.uu.se)
Date: Fri Mar 03 2000 - 12:09:36 MET


Hi Rene,

thanks for the reply. I understand that it is not convinient to add a new
data field any time somebody asks for a new functionality. Just to mention
that in case of TGraph this "attribute" array might be optional, i.e. it
will not take more than 4 bytes for a pointer if the option is not set. This
feature (different attributes for graph markers) is rather standard in other
(perhaps non-scientific:)) packages. It gives a lot of freedom and
possibilitis, for example to color a range of graph on which a fit is done,
etc. We have an application in which a beam ramp development (or position in
time/energy) is shown as a moving colored piece on a ramp graph. It is
possible to do with markers and lists of functions but it is a bit
artificial ...

Regards,
Anton

-----Original Message-----
From: brun@pcbrun.cern.ch [mailto:brun@pcbrun.cern.ch]On Behalf Of Rene
Brun
Sent: Friday, March 03, 2000 11:49 AM
To: Anton Fokin
Cc: Rene Brun; roottalk@pcroot.cern.ch
Subject: Re: TGraph drawing options


Hi Anton,
You will get may be some more inspiration from the macro below.
This macro exploits the power of the list of functions
associated with a TH1 object. The list of objects there
is obviously persistent. Just check it after having run the macro,
you can start a new session with
  Root > TFile f("anton.root");
  Root > hgr->Draw("p");

Also in the macro, note the way to specify clipping to the frame
boundary
in a pad (this applies to markers, polymarkers, lines and graphs).

I am reluctant to add this kind of functionality to TGraph.
I would like this class to be a light weight class (already too big).
If I implement an additional member as you suggest to support
color for each marker, the next client will request another array
to specify different marker styles and why not marker colors.
This is so simple to implement with TMarker.

Rene Brun

{
   gROOT->Reset();
   gStyle->SetPalette(1);
   gStyle->SetOptStat(0);
   c1 = new TCanvas("c1");
   c1->SetBit(TGraph::kClipFrame);

   TFile *f = new TFile("anton.root","recreate");
   const Int_t n = 20;
   TH1F *hgr = new TH1F("hgr","a simple graph",n,0.5,n+0.5);
   hgr->SetMarkerStyle(21);
   hgr->SetXTitle("X title");
   hgr->SetYTitle("Y title");
   for (Int_t i=1;i<=n;i++) {
      hgr->SetBinContent(i,10*sin(0.1*i));
      TMarker *m = new TMarker(hgr->GetBinCenter(i),
                           0.5*hgr->GetBinContent(i),22);
      m->SetMarkerColor(2*i+60);
      hgr->GetListOfFunctions()->Add(m);
   }
   TPaveLabel *pl = new TPaveLabel(6,1,20,2.2,
      "To show GetListOfFunctions persistency");
   hgr->GetListOfFunctions()->Add(pl);
   hgr->Draw("p");
   hgr->Write();
}


Anton Fokin wrote:
>
> Hi Rene,
>
> this is not exactly a solution I want to have. A set of markers is not a
> graph, isn't it? Apart from not be able to handle it as a single object
> (i.e. read, write, send, change attributes for each point at once), you
have
> some problems with drawing, for example with clipping (on zoom you get
> points painted outside the histogram).
>
> Best,
> Anton
>
> -----Original Message-----
> From: Rene Brun [mailto:brun@pcbrun.cern.ch]
> Sent: Thursday, March 02, 2000 11:06 PM
> To: Anton Fokin
> Cc: Rene Brun; roottalk@pcroot.cern.ch
> Subject: Re: TGraph drawing options
>
> Hi Anton,
> What you want is already implemented. I show two methods
> in the example below> I hope it is clear enough.
>
> Rene Brun
>
> {
>    gROOT->Reset();
>    gStyle->SetPalette(1);
>    gStyle->SetOptStat(0);
>    c1 = new TCanvas("c1");
>    c1->SetGrid();
>
>    const Int_t n = 20;
>    TH1F *hgr = new TH1F("hgr","a simple graph",n,0.5,n+0.5);
>    for (Int_t i=1;i<=n;i++) hgr->SetBinContent(i,10*sin(0.1*i));
>    hgr->SetMarkerStyle(21);
>    hgr->SetXTitle("X title");
>    hgr->SetYTitle("Y title");
>    hgr->Draw("p");
>    for (Int_t j=1;j<=n;j++) {
>       TMarker *m = new TMarker(hgr->GetBinCenter(j),
>                            0.5*hgr->GetBinContent(j),22);
>       m->SetMarkerColor(j);
>       m->Draw();
>    }
> }
>
> On Thu, 2 Mar 2000, Anton Fokin wrote:
>
> > Hi rooters!
> >
> > I think it would be nice to have a mode in which point number is drawn
as
> a
> > marker for TGraph. It is very useful if you want to plot, for example,
> > points from an event generator running with different sets of initial
> > conditions, i.e. 1,2,3,4,5 and you want to see a correspondence between
> set
> > number and a point on the graph.
> >
> > It would be nice of course to have an opportunity to set different
> > colors/attributes for every graph point, but it is not easy to
implement.
> > Well, it is easy if Rene adds a "fZ" array with point colors and then
> > changes a bit Paint function :)
> >
> > Best regards,
> > Anton
> >



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:20 MET