# Change x-axis label in asymptote

I'm using asymptote to make a heatmap. I have a array of values with two entries, these entries go from 0 to 50, but both represent physical quantities from 0 to 1.

I would like to have an x-axis and a y-axis which go all the way from 0 to 50 but with the label which goes from 0 to 1, does anyone know how to do this ?

I include my code so far :

``````import graph;
import palette;
import patterns;

file in=input("input.dat").line();
real[][] vals = in;

pen outside = lightgrey;

pen[] Palette = Gradient(100, white, blue);

xaxis("\$x\$",YZero,
xmin=-1,
RightTicks(Label("\$%.2g\$"),
new real[]{1,20,40,60}),
above=false);
yaxis("\$y\$",ymin = -1);

image(vals,Range(minValue,maxValue),(mx,my),(Mx,My),Palette);
``````

Thanks for the help !

Slvn

• `RightTicks(Label("\$%.2g\$"), new real[] 0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1})` gives labels from 0 to 1. – O.G. Dec 4 '17 at 21:53
• It does not give me what I would like... Let's say that I have an array A, indexed by 0, 1, 2, 3,..., 9 and I want to plot A, A,... but on the x axis I don't want the label 0, 1,... but for instance 0.1, 0.2, 0.3 instead... I'm sorry if I'm not very clear – Slvn Dec 4 '17 at 23:50

If I understand the question, you can modify the `x-axis` label by defining `ticklabel`. Following the documentation (and examples) and the graph.asy file

``````typedef string ticklabel(real);

ticklabel Format(string s=defaultformat)
{
return new string(real x) {return format(s,x);};
}
ticklabel DefaultFormat=Format();
``````

`ticklabel` returns from `x` real a string. I modified the documentation example.

``````    import graph;
import palette;

size(10cm,10cm,IgnoreAspect);

real f(real x, real y) {
return 0.9*pow10(2*sin(x/5+2*y^0.25)) + 0.1*(1+cos(10*log(y)));
}

scale(Linear,Log,Log);

pen[] Palette=BWRainbow();

bounds range=image(f,Automatic,(0,1),(100,100),nx=200,Palette);

string mod(real x)
{
return format(x/10,locale="en_US.utf8");
}

ticklabel mytick()
{
return new string(real x)
{
return  mod(x);
};
}

ticklabel mytick=mytick();

xaxis("\$x\$",BottomTop,RightTicks(mytick,
new real[]{1,20,40,60,70,95}),
above=true);

yaxis("\$y\$",LeftRight,RightTicks,above=true);

palette("\$f(x,y)\$",range,(0,200),(100,250),Top,Palette,
PaletteTicks(ptick=linewidth(0.5*linewidth())));
``````

In fact if you do not need any option in your ticklabel function, the command

``````      xaxis("\$x\$",BottomTop,RightTicks(ticklabel=mod,
new real[]{1,20,40,60,70,95}),
above=true);
``````

gives a similar result. Without specifying `new real[]{1,20,40,60,70,95})` you have 10 to 100 transformed by 1 to 10... • It was exactly what I was looking for, once again thanks @O.G. ! – Slvn Dec 6 '17 at 16:57