11

Currently, I do something like the following:

set term png
set output 'file.png'

But hardcoding filename in the script is quite inflexible. Is there some way to tell gnuplot to output image file to stdout, so I will be able to redirect it's output where needed?

2 Answers 2

14

If you do want to send your .png to stdout, just don't set the output:

#!/usr/bin/env gnuplot
set term png
plot x

Then run the script

./plot.plt > mypng.png

I think the bash wrapper makes more sense for most purposes, but this is potentially useful as well.

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

2 Comments

I, on the other hand, believe that bash wrapper is almost useless for most purposes. This is exactly what I was looking for, thanks!
For other people who might hit the same snag as me and are seeing gnuplot> in their output: don't run gnuplot - when giving commands on stdin, just pipe to gnuplot without -.
1

Put your gnuplot script inside a script and use a here document:

#!/bin/bash
gnuplot << EOF
set term png
set output "$1.png"
plot "$1.dat"
EOF

Now invoke the script, say plot.sh, by specifying the prefix to output file and data as argument: bash plot.sh file.

Comments

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.