我如何显示颜色栏



我不知道如何让颜色栏显示。我没有太多使用mayavi的经验,所以我不确定我需要采取哪些步骤才能解决这个问题?

还有其他人有类似的问题吗我的代码如下:

from tkFileDialog import askopenfilename
from StringIO import StringIO
import numpy as np 
from mayavi import mlab
#getting the data from a txt file 
filename = askopenfilename()
type(filename) 
fileAsStr =''
data = []
count= 0
atData=False
with open(filename,'r') as f:
    for line in f:
        if line.startswith("Note"):
            title = line
            title = title.strip("Note:")
            title = title.strip()
            print title
        if atData and not line.startswith('Total'):  #after the second one begin reading file
            line = line.replace(' ','')
            #data.append(line)
            fileAsStr = fileAsStr + line
        if line.startswith('-----'):
            count = count +1
        if count == 2:
            atData = True
dataStrIO = StringIO(fileAsStr)
dataArray = np.loadtxt(dataStrIO, delimiter=',')
dataDim = dataArray.shape
dx = dataArray[0:dataDim[0], 3]
dy = dataArray[0:dataDim[0], 4]
dz = dataArray[0:dataDim[0], 5]
bTotal = dataArray[0:dataDim[0],9]
firstNum = dy[0]
count = 0
while firstNum == dy[count]:
    count = count + 1
print 'count=' + str(count)
#arranging the arrays into an acceptable format
from itertools import islice
def solve(lis, n):
    it = iter(lis)
    return [list(islice(it,n)) for _ in xrange(len(lis)/n)] 
dx = np.transpose(solve(dx, count))
dy = np.transpose(solve(dy, count))
dz = solve(dz, count)
bTotal = solve(bTotal, count)
bTotal = np.log10(bTotal)

#making the plot
mlab.options.backend = 'envisage'
surf = mlab.surf(dx,dy, bTotal,warp_scale=2)
mlab.axes(surf, x_axis_visibility= True, y_axis_visibility = True, 
    z_axis_visibility = True, xlabel='x axis (mm)', ylabel='y axis (mm)', 
    zlabel ='z axis (mm)', nb_labels=10)
mlab.axes.label_text_property.font_size = 5 
mlab.title(title, line_width = .5, height = 1)
mlab.colorbar( title = "magnetic field (Tesla)")

我相信您在脚本末尾缺少mlab.show()命令。

相关内容

  • 没有找到相关文章

最新更新