简体   繁体   中英

Superimpose two Voronoi plots in Python

I'd like to superimpose two Voronoi plots in Python, but when I plot the two it just gives me two different plots ( I want both diagrams on the same plot).

Here's my code :

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)

Thanks

You need to plot both plots on the same axis

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)

在此处输入图片说明

Edit: This solution won't work with a combination of scipy 1.1- and matplotlib 3.x.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM