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);

             new real[]{1,20,40,60}),
yaxis("$y$",ymin = -1);


Thanks for the help !


  • 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[0], A[1],... 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;


    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)));


    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();

          new real[]{1,20,40,60,70,95}),



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

            new real[]{1,20,40,60,70,95}),

gives a similar result. Without specifying new real[]{1,20,40,60,70,95}) you have 10 to 100 transformed by 1 to 10...

enter image description here

| improve this answer | |
  • It was exactly what I was looking for, once again thanks @O.G. ! – Slvn Dec 6 '17 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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