asciignuplottype-conversiondata-conversion

Gnuplot: Convert integer to ASCII value


I would like to generate multiple plots within one gnuplot script, and would like to start each plot's title with a running capital letter, i.e., the first plot will have the title (A) sample title for first chart, the second one (B) sample title for second chart, and so on.

In Java, for this I basically have to do

int i = 65;       // ASCII value for 65
char c = (char)i; // Convert 65 to corresponding ASCII value ('A')
i++;
// Use c; then repeat

I just tried something similar in gnuplot by using gprintf and using the %c formatter, yet I could not get it working due to the problem

These format specifiers are not the same as those used by the standard C-language routine sprintf().

Long question short: How to convert an integer to its corresponding ASCII value?


Solution

  • gnuplot> print sprintf("%c", 65)
    #A
    

    Gnuplot also provides gprintf(), which uses gnuplot format specifiers, in addition to sprintf() with standard C-type specifiers.