def phase_diagram_mesh(points, values,
title="Phase diagram",
xlabel="Pulse Duration (s)",
ylabel="Pulse Amplitude (V)",
shading="flat",
voronoi=False, **kwargs):
# fig = plt.figure()
if voronoi:
from scipy.spatial import Voronoi, voronoi_plot_2d
points[:,0] *= 1e9
vor = Voronoi(points)
cmap = mpl.cm.get_cmap('RdGy')
# colorize
for pr, v in zip(vor.point_region, values):
region = vor.regions[pr]
if not -1 in region:
polygon = [vor.vertices[i] for i in region]
plt.fill(*zip(*polygon), color=cmap(v))
else:
mesh = scaled_Delaunay(points)
xs = mesh.points[:,0]
ys = mesh.points[:,1]
plt.tripcolor(xs,ys,mesh.simplices.copy(),values, cmap="RdGy",shading=shading,**kwargs)
plt.xlim(min(xs),max(xs))
plt.ylim(min(ys),max(ys))
plt.title(title, size=18)
plt.xlabel(xlabel, size=16)
plt.ylabel(ylabel, size=16)
cb = plt.colorbar()
cb.set_label("Probability",size=16)
return mesh
评论列表
文章目录