Closed
Description
I'm trying to add a secondary axis to one of my figures. This secondary axis is a non-linear transformation of the main one. After quite a bit of work, I got it working with:
#include "TCanvas.h"
#include "TF1.h"
#include "TGaxis.h"
#include "TH1.h"
#include "TROOT.h"
#include "TStyle.h"
void tgaxis() {
gROOT->SetStyle("ATLAS");
gStyle->SetOptStat(0);
const auto c = new TCanvas();
const auto min = 42;
const auto max = 108;
const auto h = new TH1F("", "", max - min, min, max);
const auto xa = h->GetXaxis();
xa->SetTitle("Axis");
h->Draw();
c->SetTickx(0);
c->GetPad(0)->SetTopMargin(0.15375);
c->Update();
const auto f = new TF1("f", "(72.289/x)**2", min, max);
const auto f_min = f->Eval(max);
const auto f_max = f->Eval(min);
const auto inv_f = new TF1("inv_f", "72.289/sqrt(x)", f_min, f_max);
const auto y_max = gPad->GetUymax();
const auto a = new TGaxis(min, y_max, max, y_max, f_min, f_max, 510, "-");
a->SetFunction("inv_f");
a->ImportAxisAttributes(xa);
a->SetTitle("Secondary axis");
a->Draw("same");
c->SaveAs("axis.png");
c->SaveAs("axis.root");
}
While this works with the old graphics, the result with JSROOT is not the expected one, as can be seen in the images below.
Old graphics (correct result):
New graphics (incorrect result):