#include "TCanvas.h" #include "TStyle.h" #include "TH1.h" #include "TGaxis.h" #include "TRandom.h" #include "TGraph.h" void twoscales() { gROOT->Reset(); c1 = new TCanvas("c1","Time History of Voltage/Current of 1 Channel",200,10,700,500); c1->SetFillColor(42); c1->SetGrid(); const int nrows = 10; double tVect[nrows] = {1, 200, 300, 5000, 6000, 7000, 8000, 9000, 12000, 14000}; double yVect[nrows] = {2, 3, 5, 8, 1, 4, 7, 8, 12, 14}; double xVect[nrows] = {3, 5, 4, 13, 4, 55, 6, 7, 2, 10}; TGraph *graph = new TGraph(nrows,tVect, yVect); //markers: //sets color of actual line that is graphed graph->SetLineColor(kBlack); graph->SetLineWidth(1); graph->SetMarkerColor(kBlack); graph->SetMarkerStyle(21); graph->SetTitle("Voltage and Current"); //options.. L - simple polyline, F fills area draw, A axis drawn around graph //C smooth curve drawn, * start plotted at each pt, P idem with current marker //B bar chart drawn at each pt, etc. //graph->Draw(); graph->Draw("ALP"); c1->Update(); TGraph *graph2 = new TGraph(nrows, tVect, xVect); Float_t rightmax = 1.1*graph2->GetHistogram()->GetMaximum(); Float_t scale = gPad->GetUymax()/rightmax; //graph2->SetLineColor(kBlue); double xVectPrime[nrows]; for (int counter = 0; counter < nrows; counter++){ xVectPrime[counter] = xVect[counter]*((double) scale); } *graph2 = new TGraph(nrows, tVect, xVectPrime); graph2->SetLineColor(kRed); graph2->SetLineWidth(1); graph2->SetMarkerColor(kRed); graph2->SetMarkerStyle(22); //graph2->GetHistogram()->Scale(scale); graph2->Draw("LP"); //sets space b/w axis and label graph->GetXaxis()->SetLabelOffset(0.015); //label text size graph->GetXaxis()->SetLabelSize(0.025); graph->GetXaxis()->SetTimeFormat("#splitline{%d\/%b\/%Y}{ %H:%M:%S}"); //sets divisions on x axis.. too many = labels overlap graph->GetXaxis()->SetNdivisions(5); graph->GetXaxis()->SetTimeDisplay(1); graph->GetXaxis()->SetTitle("Time"); graph->GetXaxis()->CenterTitle(); graph->GetYaxis()->SetTitle("Voltage"); graph->GetYaxis()->CenterTitle(); TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(), gPad->GetUxmax(), gPad->GetUymax(), 0, rightmax, 510, "+L"); axis->SetLineColor(kRed); axis->SetLabelColor(kRed); axis->SetTitle("Current"); axis->SetTextColor(kRed); axis->CenterTitle(); axis->Draw(); gPad->Modified(); }