Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display underscore rather than subscript in gnuplot titles

Tags:

gnuplot

Short question: How do I display the _ (underscore) character in a title in gnuplot that is assigned from a variable name in gnuplot?

Details: I have something like the following code:

items = "foo_abc foo_bcd bar_def"
do for [item in items] {
  set title item
  set output item.eps
  plot item."-input.txt" using 1:2 title item with linespoints
}

This works fine with gnuplot except that the title get changed from foo_abc to fooabc. I don't know if I want to use an escape character because I don't want that to be in the file name. I've tried a couple of different options with single vs. double quotes but I haven't found what I need yet.

like image 207
Gabriel Southern Avatar asked Dec 01 '12 00:12

Gabriel Southern


3 Answers

Instead of foo_abc, write foo\\\_abc.

like image 116
Morteza Avatar answered Nov 11 '22 14:11

Morteza


Most gnuplot commands which generate labels accept a noenhanced keyword which will prevent gnuplot from using enhanced text for just that string. In this case, it should be sufficient to just do:

set title item noenhanced

An alternative is to create a function which will remove the unwanted text from the string when passing it to set output:

remove(x,s)=(i0=strstrt(s,x),i0 ? remove(x,s[:i0-1].s[i0+strlen(x):]):s)
# Makes me wish gnuplot syntax was more pythonic :-p
#TODO:  Write a `replace` function :-).  These just might go into my ".gnuplot" file...

I use an inline function to find the index of the first occurrence of x in the string s. I then remove that occurrence via string concatenation and slicing and recursively call the function again to remove the next occurence. If the index isn't found (strstrt returns 0) then we just return the string that was put in. Now you can do:

set output remove('\',item)
set title item
like image 25
mgilson Avatar answered Nov 11 '22 12:11

mgilson


The underscore comes from treating titles as "enhanced text". Turn that off using

set key noenhanced

like image 18
Ethan Avatar answered Nov 11 '22 12:11

Ethan