在Python中叠加两个Voronoi图

时间:2018-07-24 07:57:58

标签: python matplotlib voronoi matplotlib.mlab

我想在Python中叠加两个Voronoi图,但是当我绘制两个Voronoi图时,它只是给了我两个不同的图(我希望两个图都在同一图上)。

这是我的代码:

import numpy as np 
import scipy.spatial as sp
import matplotlib.pyplot as plt 
points = np.array([[0, 0], [0, 1], [0, 2], [1, 0],[1,1],[1, 2], [2, 0], [2, 1],[2, 2]])
vor=sp.Voronoi(points)
sp.voronoi_plot_2d(vor)
point_bis=np.array([[0.5,0.5],[1,1.5],[1.5,1],[2,2.5]])
vor2=sp.Voronoi(point_bis)
sp.voronoi_plot_2d(vor2)

谢谢

1 个答案:

答案 0 :(得分:0)

您需要在同一轴上绘制两个图

import numpy as np 
import scipy.spatial as sp
import matplotlib.pyplot as plt 

fig, ax = plt.subplots()

points = np.array([[0, 0], [0, 1], [0, 2], [1, 0],[1,1],[1, 2], [2, 0], [2, 1],[2, 2]])
vor=sp.Voronoi(points)
sp.voronoi_plot_2d(vor, ax=ax)
point_bis=np.array([[0.5,0.5],[1,1.5],[1.5,1],[2,2.5]])
vor2=sp.Voronoi(point_bis)
sp.voronoi_plot_2d(vor2, ax=ax)

enter image description here