Necessity being the mother of invention, I have a patch that allows
plotting functions over only a range. The code is kinda icky but so is
the rest of the code in the function... Anyway I thought I may as well
throw it out there...
--
"But if science you say still sounds too deep,
Just do what Beaker does, just shrug and 'Meep!'"
-- Dr. Bunsen Honeydew & Beaker of Muppet Labs
Index: widgets/plotters.py
===================================================================
RCS file: /cvs/veusz/veusz/widgets/plotters.py,v
retrieving revision 1.39
diff -u -r1.39 plotters.py
--- widgets/plotters.py 1 May 2005 10:01:32 -0000 1.39
+++ widgets/plotters.py 1 Jun 2005 18:14:23 -0000
@@ -96,6 +96,12 @@
s.add( setting.Str('function', 'x',
descr='Function expression'), 0 )
+ s.add(setting.FloatOrAuto('min', 'Auto',
+ descr='Minimum value at which to calculate function'))
+
+ s.add(setting.FloatOrAuto('max', 'Auto',
+ descr='Maximum value at which to calculate function'))
+
s.add( setting.Line('Line',
descr = 'Function line settings') )
@@ -228,13 +234,21 @@
axes[0].settings.direction != 'horizontal' or
axes[1].settings.direction != 'vertical' ):
return
-
+
env = self.initEnviron()
if s.variable == 'x':
+ if not(s.min == 'Auto') and s.min > axes[0].getPlottedRange()[0]:
+ x_min = N.array([s.min])
+ x1 = axes[0].graphToPlotterCoords(posn, x_min).astype(N.Int32)[0]
+ if not(s.max == 'Auto') and s.max < axes[0].getPlottedRange()[1]:
+ x_max = N.array([s.max])
+ x2 = axes[0].graphToPlotterCoords(posn, x_max).astype(N.Int32)[0]
+
# x function
delta = (x2 - x1) / float(s.steps)
pxpts = N.arange(x1, x2+delta, delta).astype(N.Int32)
- env['x'] = axes[0].plotterToGraphCoords(posn, pxpts)
+ x = axes[0].plotterToGraphCoords(posn, pxpts)
+ env['x'] = x
try:
y = eval( s.function + ' + 0*x', env )
bad = False
@@ -245,6 +259,13 @@
else:
# y function
+ if not(s.min == 'Auto') and s.min > axes[1].getPlottedRange()[0]:
+ y_min = N.array([s.min])
+ y2 = axes[1].graphToPlotterCoords(posn, y_min).astype(N.Int32)[0]
+ if not(s.max == 'Auto') and s.max < axes[1].getPlottedRange()[1]:
+ y_max = N.array([s.max])
+ y1 = axes[1].graphToPlotterCoords(posn, y_max).astype(N.Int32)[0]
+
delta = (y2 - y1) / float(s.steps)
pypts = N.arange(y1, y2+delta, delta).astype(N.Int32)
env['y'] = axes[1].plotterToGraphCoords(posn, pypts)