I have a little problem, which is certainly easy to solve I just cannot find the answer.
I can easily superimpose 2 TGraphs, the problem is I need to scale one of the Graphs since its Y values are about 1/20 of the other Graph’s Y values. The idea is to scale the smaler graph to the size of the first one and paint a second axis on the right side of the pad. I tried painting the Graphs with the ‘A’ Option and it seemded to work but the first Graph is only visible for a split second until the other Graph is painted ontop of it. It also seems there is no scale method for the TGraph object thus the example using histogramms doesn’t apply in this case. There is one more thing that might be important. The X values don’t have the same distance to ea. other which I think poses a problem when tring to access the underlying histogramm.
The example “twoscales.C” in the turotial directory, may help you to draw a 2nd axis on your plot. I put it in attachment.To help you further (if needed) can you send a little example showing your prodblem ? that way we could modify it to answer your question. twoscales.C (1.31 KB)
Thank you for your suggestion.
Of course I already know this example. The problem is that I’m using TGraph and not a histogramm. And adding a second axis doesn’t seemd to complicated. As it seems there is no method like GetMaximum() or Scale() for TGraphs. Here is an example of my atempt:
The result is that I do get both Graphs in the same pad (as long as I don’t try calling ->Scale() ) which is fine. But the second graph is almost not visible since it’s values are too low. That’s why I thought of scaling in the first place. The reason why I don’t use histogramms is that the data isn’t random but has a exact correlation between x and y values.
If there is no easy workaround for this problem I will do it with histogramms like in the example.
Thanks again for your help
I am doing something similar, however the scales of the data are vastly different.
I took Oliver’s example code, and modified the led1.data to be 10 times smaller. The data/axes then dont scale correctly. It appears that the world coordinate system takes on the attributes of the first TGraph plotted.
What is desireable is to with the 2 different scales, actually have the second plot tied to the second scale.
This obviously means 2 world coordinate systems.
I tried modifying the code by adding the AY+ option to the second draw function. This changes the world coordinate system to the new scale of the TGraph, but does not preserve the original.
Pretty sure what I am looking for is a way to overlay 2 plots, and maintain 2 different world scales. Any options?
I’ve attached some sample code that illustrates 2 problems. The first of which is that the new Axis scale doesn’t appear to meet the x axis when a set range call has been made. The second of which is that the secondary axis, of a different scale, doesn’t match up with the values of the TGraph outlined in red.
It seems that a scale method for TGraph might be helpful. In this way the data in the second TGraph could be scaled to match the difference between the left and right. This doesn’t take into account any offset.
I also tried making 2 pads. I drew the first TGraph in the first pad and made the second pad transparent and drew the second TGraph in the second pad. This didn’t work since the bounding boxes didn’t line up, and the graph itself was not transparent.
Yes, I agree that I made it a bit unclear. Example 4 does do the trick.
I was asking if it were possible to change the transparency of a TGraph. If you look at the code in example 2, overlaid 2 TGraphs. The second uses the “AY+” option. So it scales correctly. However, the first TGraph is covered. You can find this out by using the pointer to slide the second graph to one side.
If the second TGraph were transparent, AND, I could use “AY+” such that it would not obscure the first TGraph, I could have accomplished the same feat without using a second TPad.
This may be closer to a design issue though. As I said, example4 works. I was trying to show that it was possible to gain an interesting feature in root.
As always, it is very hard to communicate without a whiteboard and a face to face.
One issue with example2.C is that one can not zoom via the empty histogram method. I tried to modify example2.C (see attachment) by adding the histogram hDummy with no luck.
When I add hDummy to pad2 I can access the hDummy object in the editor when the script is run but the “Axis Range” bars in the Binning tab do not zoom the graphs. If I add hDummy to pad1 I can only access pad2 via the editor.
The macro example2.C draws two curves in two different pads. It is done this way because the Y scales are different for the two data sets. So, as there is 2 pads, you should change the range on both (along X) to make sure the X scale remains the same for the 2 curves.