gnuplot Power Graph

Created gnuplot script file which plots 2.0D 110 kW power graphs out of two CSV files (torque & power). For CSV data origin see post Power graphs and Calculations. gnuplot experience might come handy from time to time…

Script + data files in here: gnuplotPowerGraph1.zip

By the way, thanks go to http://www.pariaonecu.com for file hosting support.

Tested on Linux, script file displays graph on screen, also creates SVG vector graphics file.
View SVG result (best, good web browser needed): PowerGraph(Subaru).svg

Raster screenshot in case you cannot view SVG:

Assuming gnuplot is installed. To run script type:
gnuplot -p 'PowerGraph(Subaru).gpl'


# gnuplot script
# Linux: gnuplot -p "thisscriptfilename"
# -p  --persist		to keep graph window

# set custom variables
fileTorque = "Torque(Subaru).csv"
filePower = "Power(Subaru).csv"
color1 = "blue"
color2 = "brown"
plotFile = "PowerGraph(Subaru).svg"

# debug: show variable content
#print fileTorque

# necessary for CSV data, input file contains comma-separated values fields
set datafile separator ","

###### terminal settings
set termoption enhanced
set term wxt font "sans,14"

###### title, labels
set title "Boxer Diesel 2.0 110 kW Power Graphs (digitized official Subaru data)"

set xlabel "Engine Speed [1/min]"
set xrange [800 : 4700]	# optional

set ylabel "Torque [Nm]" textcolor rgb color1
set y2label "Power [kW]" textcolor rgb color2

###### define linestyles
#
# 1: Torque curve
set style line 1 linetype 1 linecolor rgb color1 linewidth 3
# 2: Power curve
set style line 2 linetype 1 linecolor rgb color2 linewidth 3
# 10: grid lines
set style line 10 linetype 1 linecolor rgb "gray"

###### grid lines (independent settings for x, y, y2 are not possible?)
#set grid xtics ytics y2tics linestyle 10
set grid xtics ytics linestyle 10

###### axis tics & labels
# nomirror: don't display tic marks on other side/axis
# x axis tics+grid: increment = 200 1/min
set xtics 200
set ytics nomirror textcolor linestyle 1
set y2tics nomirror textcolor linestyle 2

set autoscale y
set autoscale y2

###### legend
# set key default
# set key bottom center box

###### plot
plot fileTorque title "Torque" with lines linestyle 1, filePower title "Power" with lines linestyle 2 axes x1y2

# quit script immediatly for debugging
#quit

pause -1 "Hit return to create SVG file"

###### SVG output (commands sent via standard input from app)
# could also do PDF, LaTeX, PNG etc.
## remember current terminal
set terminal push

# page size affects page layout, relative font size etc. - defaults may not look nice
#set terminal svg size 1200,800 dynamic enhanced font "sans,16"
set terminal svg size 1600,1000 dynamic enhanced

# plot into file, using own variable set at beginning
set output plotFile
refresh

## switch back to previous terminal
set terminal pop
refresh
######

Advertisements

One response to “gnuplot Power Graph

  1. The plotting script is well written! Even a fresh programmer (like me) can read it easily!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s