[SciPy-User] works in gnuplot, but not quite in Python/Gnuplot.py - splot (sin(x)/x) * (sin(y)/y)
Esmail
ebonak at hotmail.com
Mon Aug 3 09:52:05 EDT 2009
Hello all,
I am trying to generate a plot with Python/Gnuplot.py that I can
create interactively with gnuplot.
----------
gnuplot> set isosample 40
gnuplot> set hidden3d
gnuplot> splot (sin(x)/x) * (sin(y)/y)
----------
gives me a *beautiful* continuous plot.
I am trying to do the same with Python/Gnuplot.py - but no joy.
I have the following short Python code to generate my data which I
then funnel into a file called 'somb.dat'
----------
#!/usr/bin/env python
# somb.py
# compute the sombrero function
from math import sin
from numpy import arange
def f(x, y):
return (sin(x)/x) * (sin(y)/y)
for x in arange(-10, 11):
for y in arange(-10, 11):
print '%3d %3d %f' % (x, y, f(x, y))
print
----------
e.g.,
somb.py > somb.dat
and I use this to plot the data:
----------
#!/usr/bin/env python
import Gnuplot
g = Gnuplot.Gnuplot(debug=1)
g('set hidden3d')
g('set isosample 40')
g('set datafile missing "nan"')
g.splot(Gnuplot.File('somb.dat', with_='lines linewidth 1'))
raw_input() # to pause
----------
Is there a way to achieve the same sort of continuous output that
gnuplot generates? I tried using 0.1 as 3rd parameter for arange, but
it didn't help. I suspect the problem is with the nan values (and/or
the numeric representation in Python)?. How does gnuplot handle
this? How can I achieve the same with Python/Gnuplot.py?
Any suggestions/hints?
(I am thrilled that I can use gnuplot via Python)
Thanks,
Esmail
More information about the SciPy-User
mailing list