root(cern):如何在Unicode中用标题绘制一个数字

发布于 2025-01-30 09:42:45 字数 809 浏览 1 评论 0原文

我正在尝试通过Root-Framework(CERN)绘制一个散点图。我想用中文设置该人物的标题,但我失败了。我的设置标题的代码是

TGraphErrors graph(x,y,x_err,y_err);
char title[]=u8"圖表標題;x座標;y座標";//chinese title
graph.SetTitle(title);

,但是在图中,所有标题均在乱码文本中显示,如下图所示:

”

另外,如果我使用unicode string(即title [] = l“图表标题;x座标;y座标” ),因为graph.setTitle()不支持这一点,因此我会遇到错误。但是上面的所有字符串都可以在终端中的标准输入/输出中正确显示。因此,问题似乎不是字符串包含错误编码错误的字符,但是Root-Framework无法正确执行它们。有什么方法可以在图中显示Unicode?

PS I通过root Code.cpp运行代码,并使用G ++进行编译,但结果是相同的。我的根部版本是6.26/02,我的操作系统版本是Ubuntu 22.04。

同样,如果有一个解决方案,可以解决构建代码的方法(由G ++编译或用作根Marco),那将是很棒的。

I'm trying to draw a scatter figure via root-framework(cern). I want to set the titles of the figure in chinese, but I failed. My code for setting the title is

TGraphErrors graph(x,y,x_err,y_err);
char title[]=u8"圖表標題;x座標;y座標";//chinese title
graph.SetTitle(title);

But in the figure, all the titles are shown in garbled text as shown in the following picture shown:

figure with garbled text

Also, if I use a unicode string(i.e. wchar_t title[]=L"圖表標題;x座標;y座標"), I will get an error since graph.SetTitle() doesn't support that. But all strings above can show properly in the standard input/output in the terminal. So it seems that the question is not the string contains chars with wrong encoding, but root-framework can't perform them properly. Is there any way to show unicode in the figure?

p.s. I run the code by root code.cpp and compile it with g++, but the results are the same. My root's version is 6.26/02 and my OS version is Ubuntu 22.04.

p.s. Also, if there is a solution for both way of building the code (compiled by g++ or use as a root marco),it will be great.

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

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

发布评论

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

评论(1

撑一把青伞 2025-02-06 09:42:45

有一个肮脏的黑客:与其通过tgraph :: settitle()提供中文字符,您可以将tmathText实例放置在您希望出现的任何地方:

    gStyle->SetOptTitle(0); // no graph title please, we'll create our own

    double x1[5]{0., 1., 2., 3., 4.}, y1[5]{1., 2., 3., 4., 5.};
    TGraph* graph_one = new TGraph(5, x1, y1);
    graph_one->Draw("AP");

    (new TMathText(2.0, 5.5, "\\hbox{圖表標題}"))->Draw(); // graph title

    TMathText l_x; // x-axis title
    l_x.DrawMathText(4.0, 0.2, "\\hbox{x座標}");

    TMathText l_y; // y-axis title
    l_y.SetTextAngle(90);
    l_y.DrawMathText(-0.3, 4.5, "\\hbox{y座標}");

There is a dirty hack: instead of providing Chinese characters via TGraph::SetTitle(), you can place TMathText instances wherever you want your characters to appear:

    gStyle->SetOptTitle(0); // no graph title please, we'll create our own

    double x1[5]{0., 1., 2., 3., 4.}, y1[5]{1., 2., 3., 4., 5.};
    TGraph* graph_one = new TGraph(5, x1, y1);
    graph_one->Draw("AP");

    (new TMathText(2.0, 5.5, "\\hbox{圖表標題}"))->Draw(); // graph title

    TMathText l_x; // x-axis title
    l_x.DrawMathText(4.0, 0.2, "\\hbox{x座標}");

    TMathText l_y; // y-axis title
    l_y.SetTextAngle(90);
    l_y.DrawMathText(-0.3, 4.5, "\\hbox{y座標}");

example of a TGraph with Chinese characters in the TGraph title and in the axes titles

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文