With a few exceptions, the Curve
object
behaves in similar fashion to ordinary Python lists: The functions
append()
, extend()
and
len()
are supported (however,
insert()
is not supported). Accessing of elements or
slices of elements via the []
operator and deletion
of elements or slices of elements is supported. Iteration over the
elements is supported. Finally, the clear()
function
empties the Curve
object.
An important difference to Python lists is that the
Curve
object accepts only x/y-data, whereas the
elements in a Python list can be of any type. Whenever the
Curve
's x/y-data is modified, the view in the
Scene
object is updated immediately.
The following example demonstrates how
Curve
x/y-data is manipulated:
print 'Create Graph and Curve' g = Graph() c = Curve() g.add(c) print 'Add 4 points' c.append((0, 0)) c.append((1, 1)) c.append((2, 4)) c.append((3, 9)) print 'Remove them and re-add them in one go' c.clear() c.extend([(0, 0), (1, 1), (2, 4), (3, 9)]) print 'The length of the list and the x/y-values' print 'length =',len(c) print 'c[0] =',c[0] print 'c[1] =',c[1] print 'c[2] =',c[2] print 'c[3] =',c[3] print 'c[-1] =',c[-1] print 'c[-2] =',c[-2] print 'c[-3] =',c[-3] print 'c[-4] =',c[-4] print 'Remove the second and third points' del c[1] del c[2] print 'length =',len(c) print 'Change the value of the last point' c[-1] = (1, 1) print 'Re-initialise the list' c.clear() c.extend([(0, 0), (1, 1), (2, 4), (3, 9)]) print 'Print all values by iterating over' for xy in c: print xy print 'Sliced access' print 'c[:] =',c[:] print 'c[:-1] =',c[:-1] print 'Update the slice [1:-1]' c[1:-1] = [(1, 2), (2, 3)] print 'c[:] =',c[:] print 'Delete the slice [1:3]' del c[1:3] print 'c[:] =',c[:]