python函数veusz对象

时间:2015-03-15 21:26:06

标签: python function return

您好我正在尝试使用Veusz'组合一些功能来执行常见任务。面向对象的命令行(https://github.com/jeremysanders/veusz/wiki/EmbeddingPython)。 VszPlot(x,y)应该在列表x与y的嵌入窗口上创建初始图。然后我想要第二个函数AddPlot(x,y),它将新数据添加到同一个嵌入式图中。 VszPlot看起来像这样:

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()

这有效,但

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'

如果在VszPlot中应用,则返回此错误:

属性错误:'嵌入式'对象没有属性' graph'

我的图表属性去了哪里?

1 个答案:

答案 0 :(得分:0)

这是Veusz的具体问题。当你写graph=page.Add('graph')时,Veusz不知道你给变量的名字。在这里,新图形被分配了默认名称" graph1"。当您使用"。"导航树时,您必须使用文档中对象的真实名称。如果您需要特定名称,可以编写page.Add('graph', name='graph'),或者存储并使用变量graph