Cecilia Di Chio wrote:
> Hi,
> I've just started to use Gnuplot-py, and I'm having some trouble in
> plotting circles...
> I know that to plot circles in gnuplot one has to use the parametric
> expression x=sin(t) y=cos(t), and then plot [0:2*pi] r*sin(t)+j,
> r*cos(t)+k, where r is the radius and (j,k) the coordinates of the centre...
> My problem is that the radius and the coodinates of the centre are
> "python object" and gnuplot doesn't allow me to use them inside a
> gnuplot call.
> To clarify:
> ...
> for i in range (numOfCircles)
> r = sizeOfCircle[0,i]
> j = circlePos[:,i,0]
> k = circlePos[:,i,1]
> ...
>
> What I would like to do is
> g('plot [0:2*pi] r*sin(t)+j, r*cos(t)+k')
> but gnuplot-py doesn't recognise r, j and k ("undefined variable" error).
>
> Can anyone help me to solve this problem?
> Thanks very much,
> Cecilia
gnuplot is not really a great tool for plotting lots and lots of
circles. But if you want to do it, you could do something like:
import Gnuplot
circleparams = [
(0, 0, 1),
(1, 0, 0.2),
(0.5, 0, 0.5),
]
g = Gnuplot.Gnuplot()
g('set parametric')
g('set trange [0:2*pi]')
plotitems = []
for (x,y,r) in circleparams:
plotitems.extend([
Gnuplot.Func('%g + %g*cos(t)' % (x,r,)),
Gnuplot.Func('%g + %g*sin(t)' % (y,r,)),
])
g.plot(*plotitems)
raw_input()
Michael
|