How to correctly findbin on yaxis in tf1

Hi:

I want to customize label on y axis:

example:
#include<root/TCanvas.h>
#include<root/TF1.h>
#include<root/TAxis.h>

int main()
{
TCanvas canvas;
TF1 f("",[](auto constVariable,auto const){return std::sin(Variable[0]);},-5,5,0);
f.GetYaxis()->SetBinLabel(f.GetYaxis()->FindBin(0.),“zero”);
f.GetYaxis()->SetBinLabel(f.GetYaxis()->FindBin(0.1),“V_{0}”);
f.GetYaxis()->SetTitle(“y”);
f.GetYaxis()->CenterTitle();
f.Draw();
canvas.Print(“f.pdf”);
}

I just see -V_{0} in the output, I can not see zero in the output. Moreover, if I try:
f.GetYaxis()->SetBinLabel(f.GetYaxis()->FindBin(-0.1),"-V_{0}");
It said:
Error in TAxis::SetBinLabel: Illegal bin number: 0

Actually, my purpose is to output -V_{0} at y=-0.1, zero at 0, V_{0} at y=0.1

By definition a function has no bins along Y, and the Y axis has only one bin. That’s what you see.

root [0] TF1 f("f","x",-5.,5.);
root [1] f.GetYaxis()->GetNbins()
(Int_t) 1

Hi,
to get alphanumeric labels at the yaxis you can use a 2dim histo
like in this example:

#include "TH2F.h"
#include "TF1.h"
#include "TCanvas.h"
#include "TStyle.h"
void alphanum_yaxis()
{
	gStyle->SetOptStat(0);
	TCanvas *c = new TCanvas();
	TF1 *f = new TF1("gg", "gaus", -10, 10);
	f->SetParameters(10, 0, 2);
	TH2F *h = new TH2F("fg", "For Gaus", 100, -10, 10, 100, 0, 15);
	h->Draw();
	f->Draw("same");
	TAxis *ya = h->GetYaxis();
	ya->SetBinLabel(ya->FindBin(0.5 * f->Eval(0)), "half_max");
	ya->SetBinLabel(ya->FindBin(1.0 * f->Eval(0)), "full_max");
	c->Modified();

Cheers
Otto

Here is the final answer:

[code]#include<root/TCanvas.h>
#include<root/TF1.h>
#include<root/TAxis.h>
#include<root/TH2D.h>

int main()
{
TCanvas canvas;
TF1 f("",[](auto constVariable,auto const){return std::sin(Variable[0]);},-5,5,0);
f.SetNpx(500);
TH2D axis("","",f.GetNpx(),f.GetXmin(),f.GetXmax(),f.GetNpx(),f.GetMinimum(),f.GetMaximum());
axis.SetStats(false);
axis.GetYaxis()->SetBinLabel(axis.GetYaxis()->FindBin(-0.5),"-V_{0}");
axis.GetYaxis()->SetBinLabel(axis.GetYaxis()->FindBin(0.),“zero”);
axis.GetYaxis()->SetBinLabel(axis.GetYaxis()->FindBin(0.5),“V_{0}”);
axis.GetYaxis()->SetTickLength(0);
axis.Draw();
f.Draw(“same”);
canvas.Print(“f.pdf”);
}[/code]