# TScatter: user-defined axis range?

**URL:** <https://root-forum.cern.ch/t/tscatter-user-defined-axis-range/64166>\
**Category:** ROOT\
**Tags:** graphics, root\
**Created:** [September 18, 2025, 5:37pm UTC](https://root-forum.cern.ch/t/tscatter-user-defined-axis-range/64166 "2025-09-18T17:37:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seligman](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/b9bd4f/32.png) [@seligman](https://root-forum.cern.ch/u/seligman)\
**Post date:** [September 18, 2025, 5:37pm UTC](https://root-forum.cern.ch/t/tscatter-user-defined-axis-range/64166/1 "2025-09-18T17:37:17Z")

</div>

Is there a way to affect the axis range of a TScatter? For example, here’s plot that takes advantage of variable colors and marker sizes:

 ![tscatter](https://root-forum.cern.ch/uploads/default/original/3X/8/8/88fc6c95251e81a6eff18f6eedea744b2e8975fa.png)

The only problem is that I’d like to set the axis range to (15,15) for both axes, since that’s the size of the entire detector. Right now it’s just showing the sensors that detected the photons from an event.

I tried modifying the underlying histogram:

```auto
  auto scatterHist = scatter->GetHistogram();
  scatter->GetXaxis()->SetRangeUser(-15,15);
  scatter->GetYaxis()->SetRangeUser(-15,15);

```

From this forum post, I gather that doesn’t work, and indeed I got the errors reported in the past:

[ROOT 6.32.00: ulast \> fXmax, fXmax is used message](https://root-forum.cern.ch/t/root-6-32-00-ulast-fxmax-fxmax-is-used-message/59573)

I see that I could define a TH2 of my own, and supply it to TScatter with `SetHistogram`. But it’s not clear how I would specify both the markers and the colors via a TH2F.

Any ideas?

* * *

_ROOT Version:_ 6.34.04  
_Platform:_ macosxarm64 (Mac OS 15.6.1)  
_Compiler:_ clang version 18.1.8

* * *

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [September 19, 2025, 3:40am UTC](https://root-forum.cern.ch/t/tscatter-user-defined-axis-range/64166/2 "2025-09-19T03:40:22Z")

</div>

For the TH2 way, try disabling its statistics, then draw it before TScatter, and draw TScatter without the “A” (axis) option:

```auto
 {
   auto canvas = new TCanvas();
   canvas->SetRightMargin(0.14);
   gStyle->SetPalette(kBird, 0, 0.6); // define a transparent palette

   const int n = 4;
   double x[n] = {40, 43, 45, 47};
   double y[n] = {70, 72, 75, 77};
   double c[n] = {20, 50, 30, 40};
   double s[n] = {6, 5, 10, 4};

   auto h2 = new TH2F("h2","h2",50,20,70,40,50,90);
   h2->SetStats(0);
   auto scatter = new TScatter(n, x, y, c, s);
   scatter->SetMarkerStyle(20);
   scatter->SetTitle("Scatter plot title;X title;Y title;Z title");

   h2->Draw();
   scatter->Draw();
}

```

 ![c1](https://root-forum.cern.ch/uploads/default/original/3X/7/7/77d999512b91c85c0ac7c3ae012b82242138f1a6.png)

Notice that the title and any x and y axis titles (and labels) will be the ones from the TH2, so set those accordingly.

---

<div class="post-metadata">

**Author:** ![seligman](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/b9bd4f/32.png) [@seligman](https://root-forum.cern.ch/u/seligman)\
**Post date:** [September 19, 2025, 7:20am UTC](https://root-forum.cern.ch/t/tscatter-user-defined-axis-range/64166/3 "2025-09-19T07:20:41Z")

</div>

That did it! Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [October 3, 2025, 7:20am UTC](https://root-forum.cern.ch/t/tscatter-user-defined-axis-range/64166/4 "2025-10-03T07:20:50Z")

</div>

Closed on October 3, 2025, 7:20am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
