Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some function with a parameter that I have to plot in ROOT into a single graph for different values of the parameter. It should look like this (made in Mathematica 8):

This is my current ROOT C++ code:

Double_t v(Double_t *t, Double_t *par) {
    return par[1] * 10 / par[0] * (1-exp(-par[0]*t[0]/par[1]));

void draw() {
    TCanvas *c = new TCanvas("c", "c", 800, 600);

    TF1* fs[6];

    fs[0] = new TF1("f0", v, 0, 10, 2);
    fs[0]->SetParameters(0, 0.5);
    fs[0]->SetParameters(1, 0.1);

    fs[1] = new TF1("f1", v, 0, 10, 2);
    fs[1]->SetParameters(0, 0.5);
    fs[1]->SetParameters(1, 0.2);

    fs[2] = new TF1("f2", v, 0, 10, 2);
    fs[2]->SetParameters(0, 1.5);
    fs[2]->SetParameters(1, 0.1);

    // More functions here ...

All I get is a plot with two graphs in it, but no axes and no labels.

If I do not use Draw("same") but just Draw(), I just get one of the functions, but in a nice plot.

How could I get all into one plot? The legend is a bonus.

share|cite|improve this question
Your question is quite off-topic in this site. You should be asking in some ROOT mailing list or something similar. – Mariano Suárez-Alvarez Dec 31 '11 at 5:17
up vote 1 down vote accepted

I just tried it again, with almost the same code and get the result I want. Strange …

    TCanvas *c1 = new TCanvas("c1", "c1",30,113,800,600);

    TF1 *f5 = new TF1("f5","sin(x)",0,6);

    TF1 *f1 = new TF1("f1","cos(x)",0,6);
share|cite|improve this answer
The error you get comes from how ROOT TCanvas constructor is programmed. It uses the name to identify the TYPE of canvas it will create ... For example, if Canvas name starts with "gl" it will be ready to receive GL output. Completely moronic programming paradigm on part of ROOT. Which is why single character names are odd in ROOT. – Ahmed Masud Jan 1 '12 at 15:06
Oh, that is good to know. Thanks! – Martin Ueding Jan 1 '12 at 16:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.