Back to demo index

gnuplot demo script: approximate.dem

autogenerated by webify.pl on Sun Aug 7 20:26:40 2016
gnuplot version gnuplot 5.1 patchlevel 0
#
# Show use of pseudodata mechanism '+' to use plot styles with more than 
# one relevant value per x coordinate. In this example we use the style
# "filledcurves" to show the difference between two analytic functions.
# This corresponds to the specification of multiple columns in the 
# 'using' option for input from data files.
# 
#
approx_1(x) = x - x**3/6
approx_2(x) = x - x**3/6 + x**5/120 
approx_3(x) = x - x**3/6 + x**5/120 - x**7/5040

label1 = "x - {x^3}/3!"
label2 = "x - {x^3}/3! + {x^5}/5!"
label3 = "x - {x^3}/3! + {x^5}/5! - {x^7}/7!"

#
set termoption enhanced
save_encoding = GPVAL_ENCODING
set encoding utf8
#
set title "Polynomial approximation of sin(x)"
set key Left center top reverse
set xrange [ -3.2 : 3.2 ]
set xtics ("-π" -pi, "-π/2" -pi/2, 0, "π/2" pi/2, "π" pi)
set format y "%.1f"
set samples 500
set style fill solid 0.4 noborder

plot '+' using 1:(sin($1)):(approx_1($1)) with filledcurve title label1 lt 3, \
     '+' using 1:(sin($1)):(approx_2($1)) with filledcurve title label2 lt 2, \
     '+' using 1:(sin($1)):(approx_3($1)) with filledcurve title label3 lt 1, \
     sin(x) with lines lw 1 lc rgb "black"


Click here for minimal script to generate this plot




set encoding save_encoding