Hello,
I’d like to plot a TGraph without a frame or axes. I found how to do the latter, but not the former.
Thanks for any help,
Roger
ROOT 5.34/10 (heads/v5-34-00-patches@v5-34-10-5-g0e8bac8, Sep 04 2013, 11:52:19 on linuxx8664gcc)
Hello,
I’d like to plot a TGraph without a frame or axes. I found how to do the latter, but not the former.
Thanks for any help,
Roger
ROOT 5.34/10 (heads/v5-34-00-patches@v5-34-10-5-g0e8bac8, Sep 04 2013, 11:52:19 on linuxx8664gcc)
root [0] TCanvas *c = new TCanvas();
root [1] c->Range(-10.,-10,10,10);
root [2] TGraph *g = new TGraph();
root [3] g->SetPoint(0,-5,-5);
root [4] g->SetPoint(1,0,0);
root [5] g->SetPoint(2,5,1);
root [6] g->Draw("l")
Hello Olivier,
Thanks for your reply.
I tried your solution but get no output from the attached code:
#include "TCanvas.h"
#include "TLine.h"
#include "TAxis.h"
#include "TF1.h"
#include "TMath.h"
#include "TGraph.h"
#include "TCurlyLine.h"
#include "TArrow.h"
#include "TLatex.h"
Int_t npeaks = 1;
Int_t npx = 1000;
Double_t peaks(Double_t *x, Double_t *par) {
Double_t result = 0.0;
for (Int_t p=0;p<npeaks;p++) {
Double_t norm = par[3*p+0];
Double_t mean = par[3*p+1];
Double_t sigma = par[3*p+2];
result += norm*TMath::BreitWigner(x[0],mean,sigma);
}
return result;
}
Int_t twaddle(){
TCanvas *c = new TCanvas("c","Absorption-emission",700,550);
// c->Divide(2,1); // columns,rows
Double_t *par = new Double_t[3*npeaks];
Double_t xmin = 0;
Double_t xmax = 10;
par[0] = 2.0;
par[1] = 6.0;
par[2] = 0.1;
TF1 *emission = new TF1("emission",peaks,xmin,xmax,3*npeaks);
emission->SetNpx(npx);
emission->SetParameters(par);
// emission->Draw();
// Fill arrays and plot a TGraph
// (TF1 cannot be rotated, apparently).
Double_t *x = new Double_t[npx];
Double_t *y = new Double_t[npx];
for (Int_t i = 0; i < npx; i++) {
x[i] = xmin + i*(xmax-xmin)/npx;
y[i] = emission->Eval(x[i]);
}
TGraph *g = new TGraph(npx,y,x);
g->SetLineWidth(2);
g->SetLineColor(50);
g->SetTitle("");
// c->cd(2);
g->Draw("l");
g->GetXaxis()->SetNdivisions(0);
g->GetYaxis()->SetNdivisions(0);
c->SetSelected(c);
c->Modified();
return 0;
}
If I call g->Draw() instead of g->Draw(“l”), I get a plot.
Cheers,
Roger
Hi Roger,
But you are not doing what I told you.
You are not setting the range.
#include "TCanvas.h"
#include "TLine.h"
#include "TAxis.h"
#include "TF1.h"
#include "TMath.h"
#include "TGraph.h"
#include "TCurlyLine.h"
#include "TArrow.h"
#include "TLatex.h"
Int_t npeaks = 1;
Int_t npx = 1000;
Double_t peaks(Double_t *x, Double_t *par) {
Double_t result = 0.0;
for (Int_t p=0;p<npeaks;p++) {
Double_t norm = par[3*p+0];
Double_t mean = par[3*p+1];
Double_t sigma = par[3*p+2];
result += norm*TMath::BreitWigner(x[0],mean,sigma);
}
return result;
}
void twaddle(){
TCanvas *c = new TCanvas("c","Absorption-emission",700,550);
c->Range(0.,0.,14,11); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Double_t *par = new Double_t[3*npeaks];
Double_t xmin = 0;
Double_t xmax = 10;
par[0] = 2.0;
par[1] = 6.0;
par[2] = 0.1;
TF1 *emission = new TF1("emission",peaks,xmin,xmax,3*npeaks);
emission->SetNpx(npx);
emission->SetParameters(par);
// Fill arrays and plot a TGraph
// (TF1 cannot be rotated, apparently).
Double_t *x = new Double_t[npx];
Double_t *y = new Double_t[npx];
for (Int_t i = 0; i < npx; i++) {
x[i] = xmin + i*(xmax-xmin)/npx;
y[i] = emission->Eval(x[i]);
}
TGraph *g = new TGraph(npx,y,x);
g->SetLineWidth(2);
g->SetLineColor(50);
g->SetTitle("");
// c->cd(2);
g->Draw("l");
g->GetXaxis()->SetNdivisions(0);
g->GetYaxis()->SetNdivisions(0);
c->SetSelected(c);
c->Modified();
}
Cheers,
Olivier
Thanks Olivier. I should have paid closer attention.
Roger