在python中用绘图在线上绘制多个数据

时间:2014-08-08 12:32:12

标签: python plot vtk paraview

我正在阅读一个案件。

对于某个切片,我正在两个点之间绘制下一个绘图上线函数:

def plotoverline(Xa,Ya,Xb,Yb,Za,Zb,case,index):

    PlotOverLine1 = PlotOverLine( Source = "High Resolution Line Source" )

    PlotOverLine1.Source.Point1 = [Xa, Ya, Za]
    PlotOverLine1.Source.Point2 = [Xb, Yb, Zb]

    PlotOverLine1.Source.Resolution = nb_pts

    # saving data in CSV File
    filename = "case_" + str(case) + "_"  + str(index) + ".csv"
    writer = CreateWriter(filename)
    writer.FieldAssociation = "Points" # or "Cells"
    writer.UpdatePipeline() 

return filename

我想绘制多行并将每行的数据导出到csv文件,但我的代码只写第一行的数据和" nan"对于其他行。

Z = 200 # attitude of my slice
for i in range(le):
    Xb = left[i,0]
    Yb = left[i,1]
    Xa = pt[i,0] 
    Ya = pt[i,1] 
    data = plotoverline(Xa,Ya,Xb,Yb,Z,Z,case,ind_left[i])

1 个答案:

答案 0 :(得分:0)

我只需要指定我正在处理的spice:plotoverline函数变为:

def plotoverline(Slice, Xa,Ya,Xb,Yb,Za,Zb,case,index):

    SetActiveSource(Slice)
    PlotOverLine1 = PlotOverLine( Source = "High Resolution Line Source" )

    PlotOverLine1.Source.Point1 = [Xa, Ya, Za]
    PlotOverLine1.Source.Point2 = [Xb, Yb, Zb]

    PlotOverLine1.Source.Resolution = nb_pts

    # saving data in CSV File
    filename = "case_" + str(case) + "_"  + str(index) + ".csv"
    writer = CreateWriter(filename)
    writer.FieldAssociation = "Points" # or "Cells"
    writer.UpdatePipeline() 

return filename