Reputation: 855
I have data in a file "data" arranged in two columns i.e Bit Rate and PSNR. I want to draw gnu plot so that x-axis have title Bit rate and y-axis have title PSNR. Also show the title of graph.
set title "Rate Distortion Curve"
set xlabel "bit rates"
set ylabel "psnr"
set grid
gnuplot -p -e "plot 'data' with lp"
Upvotes: 1
Views: 1855
Reputation: 207405
Not sure what the issue is, though you seem to be mixing bash
commands and variables with gnuplot
commands and variables.
Either write an entire script for gnuplot
:
#!/usr/local/bin/gnuplot -persist
set terminal png size 1200,800
set output 'result.png'
set title "Rate Distortion Curve"
set xlabel "bit rates"
set ylabel "psnr"
set grid
plot 'data' with lp
Or, write a bash
script that calls gnuplot
as one aspect of it and which allows you the flexibility to do things with parameters and the shell before starting gnuplot
:
#!/bin/bash
# file is a bash variable set to the first parameter
file=$1
# now start gnuplot and pass variables and commands to it in a "heredoc"
gnuplot <<EOF
set terminal png size 1200,800
set output "$file"
set title "Rate Distortion Curve"
set xlabel "bit rates"
set ylabel "psnr"
set grid
plot 'data' with lp
EOF
So, if you want to be able to run this, first you make it executable - just one time is sufficient. Let's suppose you save the above file as plot
, you would do:
chmod +x plot
Then you can run it with
./plot output.png
and it will create an image file called output.png
.
In answer to your comment, if you have two lots of data to plot on the same axes, use the following - note the comma and slash at the end of the first line:
plot "data.txt" using 1:2 with linespoints title 'time', \
"data.txt" using 1:3 with linespoints title 'size'
The above assumes your data looks like this, in 3 columns:
10 1.32632 1.8897552
11 1.33474 1.9563009
12 1.37261 2.0283514
Upvotes: 3