Changing labels size on TF1 and TGraph


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi,

is there a way to change TF1, TGraph axes parameters like in TH1?

I know that TF1 and TGraph mechanisms are different and one has to use painter after draw to change axes colors, axes labels size etc but using this with awaits is a bit complicated and not so clean (i let users to create JSROOT graphs in ace code editor).

Maybe you plan to put such an option (ex. just using f1.fXAxis.fLabelsSize = 0.07) in the future that is why i am asking, so if you do let me know.

Regards,

Georgios

Hi Georgios,

If you create objects with JavaScript, you can use following code:

      import { createTGraph, createHistogram, draw } from 'jsroot';
      const npoints = 5, xpts = [1,2,3,4,5], ypts = [3,5,3,5,3];
      const graph = createTGraph(npoints, xpts, ypts);
      const h1 = createHistogram('TH1I', 20);
      h1.fName = 'axis_draw';
      h1.fTitle = 'Graph title';
      h1.fXaxis.fLabelSize = 0.05;
      graph.fHistogram = h1;
      draw('divid', graph, 'AL');

Some of such examples you will find in: https://github.com/root-project/jsroot/tree/master/demo

like: JavaScript ROOT API examples

Regards,
Sergey

Thanks for the link,

this wont work for me,

i see now the new histogram with axes labels correctly changed, but graph line went away!

Here is a code that works but it is not good enough for users who are typing simple javascript JSROOT commands in a code editor

let f1 = create("TF1", "sin(x)/x", -Math.PI, Math.PI);
f1.fName = "f1";

let f2 = create("TF1", "sin(x)*x", -Math.PI, Math.PI);
f2.fName = "f2";
f2.fLineColor = 3;

let l = create("TList");
l.arr = [f1, f2];

let painter = await draw(l, 'gridxy');

let main = painter.getMainPainter();
main.getHisto().fXaxis.fLabelSize = 0.08;
await painter.redrawPad();

i mean the last part is a bit hard for them.

Hi,

I add draw_graph.htm demo to repository.

   <script type='module'>
      import { draw, createTGraph, createHistogram, kNoStats } from 'jsroot';
      const npoints = 5, xpts = [1,2,3,4,5], ypts = [3,5,3,5,3];
      const graph = createTGraph(npoints, xpts, ypts);
      graph.fTitle = 'Graph title';
      graph.fLineColor = 3;
      graph.fLineWidth = 4;
      graph.fLineStyle = 2;
      const h1 = createHistogram('TH1I', 20);
      h1.fName = 'axis_draw';
      h1.fXaxis.fLabelSize = 0.05;
      h1.fXaxis.fXmin = 0;
      h1.fXaxis.fXmax = 6;
      h1.fMinimum = 0;
      h1.fMaximum = 8;
      h1.fBits |= kNoStats;
      graph.fHistogram = h1;
      draw('drawing', graph, 'AL*');
   </script>

Here is link: https://jsroot.gsi.de/dev/demo/draw_graph.htm

Regards,
Sergey

This is also possible way - but leads to small “flicking” when drawing graph

Neither is a solution in my opinion, nor yours nor mine.

A user would waiting to use the same simple technique for changing axes parameters simply (with graph.fXAxis.fLabelsSize) for all graphical containers (TF1, TGraph, TH1).

But since it is difficult to achieve such a solution we will use some workarounds.

Best regards,

Georgios