1

I have many charts, each generated by individual Gnuplot (5.0) files and individual data files. They all share common display characteristics such as background, font, etc. Occasionally, there is a call to change the look of all the charts--for example, change the background color of all charts from "#000000" to "#333333".

To continue with the example, what I would like do is place the color value into a textfile called "backgroundColor.txt" and then pull that value into each file as it's plotted. Even better would be to have background color preference on the first line, font on the second, etc.

Example textfile.txt:

"#000000"
"Arial,10"

Gnuplot psuedo-code:

backgroundColor_var = file[1]
font_var = file[2]

set terminal pngcairo enhanced background backgroundColor_var font font_var size 600,200

Then I need make only one change, rather than many, many changes. Thanks in advance,

Dave

2 Answers 2

2

Why don't you simply put the whole variable declaration in the config file?

File textfile.txt:

backgroundColor_var = "#FFFFFF"
font_var = "Arial,10"

And then use it with

load 'textfile.txt'
set terminal ...

This solution works on any OS and you can put everything inside, line style definitions, terminal settings, fonts and so on

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

1 Comment

I looked at 'Load' and dismissed it for some reason. Probably because I thought it had to be more complicated than this. Thanks Christoph, this is a great solution.
1

I would use the system command. In linux, the following should work:

config = "config.cfg"
backgroundColor_var = system( sprintf("sed -n '1p' %s", config) )
font_var = system( sprintf("sed -n '2p' %s", config) )

The sed -n 'Np' command selects the Nth line of the config file. In windows, you would need to install gnuwin32 to use this answer.

4 Comments

Thanks for the pointer. Your suggestion is VERY close. When I print the variable value, I get the value I'm looking for: "#FFFFFF"; however, when I add the variable to the set terminal command, I get the following error: unrecognized color name and not a string "#AARRGGBB" or "0xAARRGGBB".
I figured it out (the error was mine.) I mistakenly put double quotes around the value inside the parameter file--effectively giving me ""#FFFFFF"" where it mattered. Once I removed those, it worked perfectly. Thanks vagoberto for the perfect solution.
Well, it is not perfect :) Christoph's answer is easier. My answer would be suitable for more complicated tasks (for example, read the header of a datafile)
I was when I commented! :) But I agree, I had to give the answer to Christoph. Thanks for responding nonetheless. I will keep that one in my back pocket for when I need it. Cheers.

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.