Hi Satya,
If you use a TVector instead of vector, you can pass 2 TVectors to
the constructor of TGraph, and
it will automatically build the graph with points taken as
corresponding entries of the vectors (the vectors
don't even need to be the same length, it will set number of points =
minimum of the 2 lengths)
if you must use a vector, you could do something like
vector<Float_t>::iterator v1iter=v1.begin();
vector<Float_t>::iterator v2iter=v2.begin();
TGraph* graph = new TGraph(v1.size());
Int_t curpoint=0;
while(v1iter!=v1.end() && v2iter!=v2.end())
graph->SetPoint(curpoint++,*(v1iter++),*(v2iter++));
(I have assumed they are vectors of Float_t, modify depending on what
you actually use)
The problem with this is that it duplicates all the data and stores
it in a graphs, so obviously if these
vectors are big, this isn't a good idea. The following might work
better in that case:
TGraph* graph = new TGraph(v1.size());
Int_t curpoint=0;
for(Int_t i=0; i<v1.size();i++){
graph->SetPoint(curpoint++,v1.at(v1.size()),v2.at(v2.size()));
v1.pop_back();
v2.pop_back();
}
this will destroy the vectors, and transfer their contents into the
graph.
(This code should work properly, but I recommend trying it on an
unimportant vector first before
letting it run over any important data, since it does destroy the
vectors).
Alexander Mott
armott_at_mit.edu
Department of Physics
Massachusetts Institute of Technology
On Aug 4, 2006, at 9:08 AM, Satya J wrote:
> Dear Rooter,
>
> Can sombody help me in the following: I filling some data to two
> vectors.
> I am sure that the dimension must be same for both vector, but
> dimension
> is dynamic.
>
> v1.push_back(x);
> v2.push_back(y);
>
> now I want to plot them v1 as x-axis v2 as y-axis.
> and the dimension can be
> n=v1.size();
>
> kindly suggest how I can plot.
> Thanks,
> Satya
>
Received on Fri Aug 04 2006 - 17:21:27 MEST
This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:00 MET