Hi I'm trying to put together some functions to perform common tasks using Veusz' object oriented command line (https://github.com/jeremysanders/veusz/wiki/EmbeddingPython). VszPlot(x,y) should create an initial plot on an embedded window of the lists x against y. I then want to have a second function AddPlot(x,y) which will add the new data to the same embedded plot. VszPlot looks like this:
def VszPlot(xval,yval):
#Create a default veusz graph. Visualise with option to save
import veusz.embed as veusz
# construct a Veusz embedded window
# many of these can be opened at any time
handle = veusz.Embedded('Graph')
# construct the plot by adding widgets
page = handle.Root.Add('page')
graph = page.Add('graph')
xy1 = graph.Add('xy',xData = xval, yData = yval)
xy1.MarkerFill.color.val = 'red'
return handle
def AddPlot(handle,xval,yval):
# try and do something to handle
handle.EnableToolbar()
This works, but
def AddPlot(handle,xval,yval):
#try and do something to some property of an attribute. eg change colour of markers
handle.graph.xy1.MarkerFill.color.val = 'blue'
which would work if applied inside VszPlot returns this error:
AttributeError: 'Embedded' object has no attribute 'graph'
Where has my graph attribute gone?
This is a Veusz specific question. When you write
graph=page.Add('graph')
, Veusz doesn't know the name you gave the variable. Here, the new graph is assigned the default name "graph1". When you're navigating the tree with ".", you have to use the real name of the object in the document. If you want a particular name, you can writepage.Add('graph', name='graph')
, or store and use the variablegraph
.