Graph with strings as x axis

Is there a problem here? Assume the vectors are valid when passed in.

void plot(vector<double> conc, vector<string> date) {
    //x and y axis of graph
    double x[conc.size()];
    double y[conc.size()];
    string z[date.size()];
    for (int i = 0; i < conc.size();i++) {
        x[i] = i;
        y[i] = conc.at(i);
        z[i] = date.at(i);
    }
    auto graph = new TGraph(conc.size(), x, y);
    graph->SetMarkerStyle(20);
    GraphDoubleString(graph,z);
    delete graph;
}

when you use the macro I sent you as I suggested in my first post, does it work for you ?

Yes, when I run that code it does work.

So it should be used that way . Can you post something reproducing what you are doing ?

What does that mean? Should I post files, or code or a description?

Some code I can run to test what you are doing. The macro I sent you works when used I instructed. You are surely using it in some other way. I need to see (and try) what you do.

Link
Note the col global variable at the top of the macro, and the path you need to change in the macro’s list_files function. The main function is at the bottom and the relevant functions to this bug are near the bottom. I’ve thrown your macro in but it’s not working. I’m going to check the arrays real quick.

I added a local col to DrawLabels(), should probably be removed

I made a simpler version
plot.C (1004 Bytes)

root [0] .x plot.C

Almost perfect.


This might be inevitable, but the words are horizontal Can I make them vertical? Also, how can I save the canvas to pdf?

Got the text angle with t->SetTextAngle(90);

Is there a list of SetTextAlign and SetTextFont etc. options? If it’s in the documentation I must be missing it.

Text attributes are described here:
https://root.cern/doc/master/classTAttText.html

Ok I just used a for loop to test:
image
How can I access the canvas to make it bigger and save it as a pdf progamatically?

void plot() {
   auto c = new TCanvas("c", "c", 1000, 800);
   Double_t x[3] = {1,2,3};  
   Double_t y[3] = {1,5,2}; 
   std::string colour[3] = { "Blue", "Red", "Green"}; 

   auto gr = new TGraph(3,x,y);
   gr->SetMarkerStyle(20);
   GraphDoubleString(gr,colour);
   c->Print("c.pdf");
}

Perfect. Thank you. Is there a solution to the macro within a macro question? It has been pertinent in other parts of this project too.

I do not understand what you mean …

Wow … difficult to follow ! … yes you can execute a macro using Processline. but if that particular ca I do not think it will help.

I wanted to call your macro earlier because it clearly worked when calling the macro, but not when I pasted your macro into mine. The problem was that I couldn’t reference things like “gr” and “color” because those were declared in c and not in root. This is why I was wondering if I could execute a macro in a programmatic way.