Draw a circle in gnuplot

Here’s the content of the script I will use with gnuplot to make a graph of a circle using Cartesian coordinates. Save the file as ‘circle.gpt’ and run as a script with command ‘gnuplot circle.gpt’. Alternatively you could write the commands in gnuplot using the interactive mode.

set terminal png

set nokey
set xrange[-10:10]
set yrange[-10:10]

set output "circle.png"
set samples 100000
r = 5.0 ## radius 
a = 3.0 ## x shift
b = 4.0 ## y shift

f1(x) = sqrt(r**2 - (x-a)**2) - b
f2(x) = sqrt(r**2 - (x-a)**2) + b

plot f1(x) lw 3, -1*f2(x) lw 3 lt 1

Circle plotted with above script

For notation I followed the great handout available here: http://www.eclecticon.info/maths%20-%20geometry.htm — topic of the handout is Cartesian equation of a circle.

Explanation from Khan academy


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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s