python - Matplotlib tripcolor bug? -


i want use tripcolor matplotlib.pyplot view colored contours of of data.

the data extracted xy plane @ z=cst using paraview. directly export data in csv paraview triangulates plane me.

the problem depending on plane position (ie mesh) tripcolor gives me or bad results.

here simple example code , results illustrate it:

code

import matplotlib.pyplot plt import numpy np  p,u,v,w,x,y,z  = np.loadtxt('./bad.csv',delimiter=',',skiprows=1,usecols=(0,1,2,3,4,5,6),unpack=true)  nblevels = 256  plt.figure() plt.gca().set_aspect('equal')  plt.tripcolor(x,y,w,nblevels,cmap=plt.cm.hot_r,edgecolor='black')  cbar = plt.colorbar() cbar.set_label('velocity magnitude',labelpad=10)  plt.show() 

results tripcolor

enter image description here

here file causes problem.

i've heard matplotlib's tripcolor buggy, bug or not ?

as highlighted @hooked normal behaviour delaunay triangulation. remove unwanted triangles should provide own triangulation passing explicitly triangles.

this quite easy in case data structured: suggest performing delaunay triangulation in plane (r, theta) passing these triangles initial (x, y) arrays. can make use of the built-in trianalyzer class remove flat triangles (r, theta) triangulation (they might exists due round-off errors).

import matplotlib.pyplot plt import numpy np import matplotlib.tri mtri  p,u,v,w,x,y,z  = np.loadtxt('./bad.csv',delimiter=',',skiprows=1,usecols=(0,1,2,3,4,5,6),unpack=true)  r = np.sqrt(y**2 + x**2) tan = (y / x) aux_tri = mtri.triangulation(r/np.max(r), tan/np.max(tan)) triang = mtri.triangulation(x, y, aux_tri.triangles) triang.set_mask(mtri.trianalyzer(aux_tri).get_flat_tri_mask())  nblevels = 256  plt.figure() plt.gca().set_aspect('equal')  plt.tripcolor(triang, w, nblevels, cmap=plt.cm.jet, edgecolor='black')  cbar = plt.colorbar() cbar.set_label('velocity magnitude',labelpad=10) plt.show() 

enter image description here


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -