How to draw a new histogram with old (xmin, xmax)

Dear rooters,

when SetLogy() is called in a canvas, all the histograms to be drawn in this canvas will have log scale on y axis. But if I zoom in a histogram on a canvas, and then draw on the same canvas a new histogram, the old zoomed view is gone. This is because the log scale is set by the canvas while the range of axis is taken care by the histogram itself. Is there an easy way to tell the canvas to keep the old x axis range? What I can image is that I save the old xmin and xmax manually and then SetRangeUser() before drawing the new histogram. But what if I also want to keep the same title and some other properties? Shall I save them all manually? Or is it possible to ask ROOT to adapt automatically some of the properties from the previous histogram?

To be more concrete, I fetch a histogram from a server through network, which is updated, say, every 30 second, and draw it on a canvas. I then zoom in to a special region of the histogram on the canvas by mouse. This view is gone when a new version of histogram is drawn in the same canvas.

Cheers, Jing

I cannot reproduce what you are describing here. Can you send a small macro reproducing what you mean ?

  • I plot an histo.
  • go in log scale on the Y axis
  • zoom the x axis
  • plot and histo using “same”…
    The X axis stays with the zoomed range.

Thank you, I didn’t use the “same” option, I just cd to the canvas and draw the new histogram. By the way, when the “same” is used, how do you remove the old histogram and resale the y axis to allow the new histogram fitting in?

Cheers, Jing

[quote]To be more concrete, I fetch a histogram from a server through network, which is updated, say, every 30 second, and draw it on a canvas. I then zoom in to a special region of the histogram on the canvas by mouse. This view is gone when a new version of histogram is drawn in the same canvas.[/quote]Humm … what you would like to see is the data in the histogram to be refreshed but the view to not change whenever you receive a new histogram. In this case we recommend that instead of doing h->Draw() each time, you do h->Draw() only once and upon receiving the new data you do: h->Reset(); h->Add( newhisto ); mycanvas->Modified(); mycanvas->Update();The only limitation is that this requires the histogram to always have the same limit and number of bins.

Cheers,
Philippe.

[quote=“pcanal”]

h->Reset(); h->Add( newhisto ); mycanvas->Modified(); mycanvas->Update();
Cheers,Philippe.[/quote]

Well, this would do what I want. Thank you very much!

Cheers, Jing