I need build vertical line on my graphic. For example: x=0. How can I make it?
Please read tips for efficient and successful posting and posting code
ROOT Version: 6.19/01
Platform: Ubuntu
Compiler: Not Provided
I need build vertical line on my graphic. For example: x=0. How can I make it?
Please read tips for efficient and successful posting and posting code
ROOT Version: 6.19/01
Platform: Ubuntu
Compiler: Not Provided
Hi,
you can use the TLine object.
Cheers,
Stefano
TLineObject->Draw() doesn’t work. I haven’t line on my dask.
Something like this should work
//your code
TLine *v_line= new TLine(0,-2,0,3); //declare the vertical line
//Set line attributes
v_line->SetLineColor(kRed);
v_line->SetLineWidth(2);
v_line->SetLineStyle(kDashed);
//draw the line
v_line->Draw("same");
Stefano
I made vector<TLine> lines and work with it. lines[i].Draw() doesn’t work. All part of my code:
...
void DrawWalls(vector<double>& walls)
{
vector<TLine> lines(walls.size());
for ( int i = 0; i < walls.size(); i++ )
{
lines[i].SetX1(walls[i]);
lines[i].SetX2(walls[i]);
lines[i].SetY1(0);
lines[i].SetY2(0.4);
}
for ( int i = 0; i < walls.size(); i++ )
lines[i].Draw();
}
Hi,
You create TLine objects in stack and they are destroyed immediately after leave of function scope.
Just create TLine objects dynamically:
vector<TLine*> lines(walls.size());
for ( int i = 0; i < walls.size(); i++ )
{
lines[i] = new TLine();
lines[i]->SetX1(walls[i]);
lines[i]->SetX2(walls[i]);
lines[i]->SetY1(0);
lines[i]->SetY2(0.4);
}
for ( int i = 0; i < walls.size(); i++ )
lines[i]->Draw();
yes, it works, thanks
As a side note: The “same” option is not a TLine Drawing option.
TLine::Draw() is the generic Draw() method inherited from TObject, therefore it has no option. Simply use v_line->Draw();
You can also create a single TLine l;
And if all line should use same style, call
l.DrawLine( xmin, ymin, xmax, ymax).
I.e you can drop the vector if you want.