matplotlib conversion

Script to convert the .xml files (ParaView format) into the Matplotlib format.

import matplotlib as mpl

import numpy as np

from xml.dom import minidom

## source of this function:

def make_cmap(colors, position=None, bit=False):

if len(position) != len(colors):

sys.exit(“position length must be the same as colors”)

elif position[0] != 0 or position[-1] != 1:

sys.exit(“position must start with 0 and end with 1”)

cdict = {‘red’:[], ‘green’:[], ‘blue’:[]}

for pos, color in zip(position, colors):

cdict[‘red’].append((pos, color[0], color[0]))

cdict[‘green’].append((pos, color[1], color[1]))

cdict[‘blue’].append((pos, color[2], color[2]))

cmap = mpl.colors.LinearSegmentedColormap(‘my_colormap’,cdict,256)

return cmap

## load source xml file

xmldoc = minidom.parse(‘yellow6.xml’)

itemlist = xmldoc.getElementsByTagName(‘Point’)



for s in itemlist:





## construct the colormap

mycmap = make_cmap(color_vals,data_vals)

print ‘converted successfully!’

# mycmap is matplotlib compatible object. to query color value out of it:

print ‘example rgba value for data value 0 is: ‘ + str(mycmap(0.0))