1

I am using a gnuplot plot loop to plot data from several plots together:

filenames = "my data files"
plot for file in filenames file.".txt" \
title file

Right now I'm using title file to set the plot title, but I'd like more control over the plot title without resorting to changing my file names. For example, in pseduocode, I'd like:

files = [first, second, third, fourth]
titles = [One title, second title, third title, fourth title]
plot for [n=1:4] files[n] titles[n]

Note that the titles consist of multiple words, so words(titles,n) is not an option. Is there another method I can use to give me more flexibility in my titles?

2
  • Could you specify what you mean by "more flexible"? In general, gnuplot supports the sprintf() command known from C. But if you have filenames, only, there's not much you can do. But if your filenames contain a series of numbers, you can use something like plot for [i=1:10] sprintf("file%d.txt", i) title sprintf("Dataset %d",i) Commented Dec 5, 2014 at 14:34
  • @sweber question edited to clarify. Commented Dec 5, 2014 at 14:51

2 Answers 2

4

First of all: good news, the 5.0 version has limited support for quoting text parts for use with word and words.

With version 5.0RC3, the following works fine:

titles='"first title text" "second title text"'
plot x title word(titles, 1), 2*x title word(titles, 2)

A second 'hack' would work with the postscript terminal, in case you are using it, and encodes the space inside the title with its octal representation \040:

set terminal postscript eps enhanced
set output 'spaces.eps'
titles='first\040title\040text second\040title\040text'
plot x title word(titles, 1), 2*x title word(titles, 2)

A third version uses a replacement character for the spaces and a shell call to sed to insert the spaces after the splitting:

titles='first@title@text second@title@text'
sub(s) = system(sprintf("echo \"%s\" | sed 's/@/ /g'", s))
plot x title sub(word(titles, 1)), 2*x title sub(word(titles, 2))

You could also setup a function myword, which uses awk or similar to do the splitting directly. But that would probably require some fiddling with quote characters.

Sign up to request clarification or add additional context in comments.

Comments

0

This is indeed possible using word(string_with_words, index) :

filenames = "my data files"
description= "one two three"

plot for [n=1:4] word(filenames, i) title word(description, i)

1 Comment

I'm familiar with words. Unfortunately, I want titles that are more than one word.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.