使用 Cern ROOT 绘图

发布于 2024-11-15 10:26:48 字数 235 浏览 2 评论 0原文

我正在尝试创建一个图表并将其另存为图像。我需要使用ROOT。我创建了图表,

TGraph graph = TGraph(xvect, yvect);

但现在我陷入了如何将其保存为 png(或其他图像格式)的困境。我正在使用 Linux 机器,如果这有什么区别的话。另外,如果有人知道描述将图形写入图像文件的方法的文档链接,我可以从那里自己找出答案,但到目前为止我还没有在文档中成功找到它。

I am trying to create a graph and save it as an image. I am required to use ROOT. I created the graph with

TGraph graph = TGraph(xvect, yvect);

but now I'm stuck on how to get that saved as a png (or other image format). I'm using a linux machine if that makes a difference. Also, if anyone knows link to the documentation that describes the method for writing the graph to an image file, I could figure it out myself from there, but I have been unsuccessful in finding that in the documentation thus far.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

嘴硬脾气大 2024-11-22 10:26:48
TCanvas*c1 = new TCanvas();
graph->Draw();
c1->Print("name.png");

肯定会在 cint shell 中工作。它可能需要一些微调才能在编译的代码中工作。

您会发现所有这些基本内容都在在线教程和< a href="http://root.cern.ch/drupal/content/howtos" rel="nofollow">HowTos。另请参阅一般文档

TCanvas*c1 = new TCanvas();
graph->Draw();
c1->Print("name.png");

Will certainly work in the cint shell. It may need some fine-tuning to work in compiled code.

You'll find all this basic stuff exhaustively covered in the on-line tutorials and HowTos. Also see the documentation in general.

与风相奔跑 2024-11-22 10:26:48
TCanvas*cvs = new TCanvas();
graph->Draw();
cvs->SaveAs("name.png");

SaveAs 是我在根目录中保存图形的常用函数。
附带说明一下,正如 dmckee 所说,在线文档非常有用。
班级列表

TCanvas*cvs = new TCanvas();
graph->Draw();
cvs->SaveAs("name.png");

SaveAs has been my go to function for saving graphs in root.
As a side note the online documentation is very useful as dmckee said.
class list

寄风 2024-11-22 10:26:48

完整的宏将是:

TCanvas *c1 = new TCanvas();
const Int_t n = 10;
Double_t xvect[n];
Double_t yvect[n];
.... initialize xvect and y vect
TGraph graph = TGraph(n, xvect, yvect);
graph->Draw("al"); // draw the graph as a line (see the ROOT wen site for more option)
c1->SaveAs("c1.png"); // many other formats are available (PS, PDF, JPEG etc...)

The complete macro will be:

TCanvas *c1 = new TCanvas();
const Int_t n = 10;
Double_t xvect[n];
Double_t yvect[n];
.... initialize xvect and y vect
TGraph graph = TGraph(n, xvect, yvect);
graph->Draw("al"); // draw the graph as a line (see the ROOT wen site for more option)
c1->SaveAs("c1.png"); // many other formats are available (PS, PDF, JPEG etc...)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文