Hi,
Is there any simple way to let the y axis go from larger value to smaller value (bottom to top) on the graph.
Hi,
Is there any simple way to let the y axis go from larger value to smaller value (bottom to top) on the graph.
Duplicated:
Thank you, I can’t figure out why it has no influence on the axis I draw, can you take a look at my code
#include “TCanvas.h”
#include “TH1.h”
#include “TGraph.h”
#include “TAxis.h”
#include “TGaxis.h”
//This program reads data from the table2.txt file and plot the fourth and sixth colomn as x and y
void ReverseYAxis (TH1 *h);
void Astro () {
TGraph *g = new TGraph("/Users/kumakenkoji/Desktop/table3.txt", "%*s %*s %*s %lg %*s %lg");
TCanvas *c1 = new TCanvas ("c1", "canvas1", 200,10,600,400);
g->GetYaxis()->SetTitle("V mag");
g->GetXaxis()->SetTitle("B-V");
g-> Draw("A*");
ReverseYAxis(g);
}
// reverse Yaxis
void ReverseYAxis (TH1 *h)
{
//Remove the current axis
h->GetYaxis()->SetLabelOffset(999);
h->GetYaxis()->SetTickLength(0);
//Redraw the new axis
gPad->Update();
TGaxis *newaxis = new TGaxis(gPad->GetUxmin(),
gPad->GetUymax(),
gPad->GetUxmin()-0.001,
gPad->GetUymin(),
h->GetYaxis()->GetXmin(),
h->GetYaxis()->GetXmax(),
510,"+");
newaxis->SetLabelOffset(-0.03);
newaxis->Draw();
}
Astro.C (1.21 KB)
Yes, I’m using your code, but when I inserted part of your code (Yaxis) into mine, it doesn’t change anything of my graph, I don’t understand why, it would be great you can check it. Thank you
Right after “Draw”, try to add:
gPad->Modified(); gPad->Update();
I don’t think it works, never mind, I’ll use Excel…
Thank you though.
Your macro had some mistakes.
attached is a working version.
Astro.C (1.33 KB)
Thank you for paying attention to my problem and I corrected the mistake with the variable taken with the method and now the y axis is upside down, but the position for data points don’t change accordingly, is that just what it is ?
Ah yes … the data do not change… That’s only the axis. The data should be changed “by hand”.
There is now a function that inverts the data points, so that you do not need to do that by hand: