How to drawclone tf1 with axis title

Because my drawing function is very complex, so I want to put it in a function, but I can not drawclone the axis title. The following is the test code. Any idea to drawclone tf1 with axis title?

#include<root/TF1.h>
#include<root/TCanvas.h>
#include<root/TAxis.h>

void draw(TCanvas&canvas)
{
TF1 f1{"",“sin(x)/x”,0,10};
f1.GetXaxis()->SetTitle(“hahaha”);
f1.GetXaxis()->CenterTitle();
f1.GetXaxis()->DrawClone();
f1.DrawClone();
}

int main()
{
TCanvas canvas;
draw(canvas);
canvas.Print(“test.pdf”);
}

Thanks to report. I see the issue you mention. I’ll check.

Try: void draw(TCanvas &canvas) { TF1 f1("", "sin(x)/x", 0, 10); TF1 *f = f1.DrawCopy(); // ... or ... ((TF1*)(f1.DrawClone())) f->GetXaxis()->SetTitle("hahaha"); f->GetXaxis()->CenterTitle(); canvas.Modified(); canvas.Update(); }

Yes, looking at the way it is done in the code, I think Pepe is right… Setting the title after DrawClone is the way to proceed.

Thank you, it works.

I am quite weird why the drawclone function of tf1 not copy the axis title. Because drawclone of tgraph will copy the axis title at the same time. Is it a bug?