1
votes

I am trying to plot some data with en ellipse on top in gnuplot. I want to plot the ellipse parametrically, and not using set object ellipse.

The following code will plot the data:

plot "my_file.dat" u 1:2

The following code will plot the ellipse:

x0 = 1
y0 = 2
a = 3
b = 2
f(t) = x0 + a*cos(t)
g(t) = y0 + b*sin(t)
set parametric
plot [0:2*pi] f(t),g(t)

How do I combine these plots in a single plot?

I am running gnuplot 5.2.

2

2 Answers

0
votes

Well, check the gnuplot manual or on the gnuplot console help plot.

Syntax:

  plot {<ranges>} <plot-element> {, <plot-element>, <plot-element>}

Simply add a plot element separated by comma. For better readability you may want to put it into a new line using \ as last character of the previous line.

plot [0:2*pi] f(t),g(t), \
     "my_file.dat" u 1:2
1
votes

Any plot command in parametric mode can be reformulated to produce the same plot in non-parametric mode using the pseudofiles '+' for one parametric variable or '++' for two parametric variables.
So your

set parametric
plot [0:2*pi] f(t),g(t)

is exactly equivalent to

unset parametric
plot sample [t=0:2*pi] '+' using (f(t)) : (g(t))

In this form it is trivial to mix it with other data plots.