当我尝试在两个子批次中显示线条集合时,没有显示。当我只在第一个显示时,它就起作用了。我怎么都能在里面展示?在
import numpy
import matplotlib.delaunay
from matplotlib import pyplot as plt
from matplotlib.collections import LineCollection
# Unique points
points = numpy.random.randint(0,2000, (1000, 2))
points = numpy.vstack([numpy.array(u) for u in set([tuple(p) for p in points])])
# Delaunay edges
centers, edges, tris, neighb = matplotlib.delaunay.delaunay(points[:,0], points[:,1])
# LineCollection of edges
lc_edges = LineCollection(points[edges])
# 1x2 subplots
fig,(ax) = plt.subplots(1, 2, figsize=(12,16))
ax1 = plt.subplot(211, aspect='equal', xlim=[points[:,0].min()- 100, points[:,0].max() + 100], ylim=[points[:,1].min() - 100, points[:,1].max() + 100])
plt.title("First plot")
plt.gca().add_collection(lc_edges)
plt.scatter(points[:,0], points[:,1])
ax2 = plt.subplot(212, aspect='equal', xlim=[points[:,0].min()- 100, points[:,0].max() + 100], ylim=[points[:,1].min() - 100, points[:,1].max() + 100])
plt.title("Second plot")
#plt.gca().add_collection(lc_edges)
plt.scatter(points[:,0], points[:,1])
fig.savefig('myfile.png', dpi=250)
plt.close()
编辑:
真正的问题是“LineCollection对象是否可以重用?”在
您可以使用copy module制作lc_edges的卷影副本。lc\u edges2和lc\u边都将使用相同的路径列表,您可以通过以下方法进行确认:
lc_edges._paths is lc_edges2._paths
。在结果如下:
相关问题 更多 >
编程相关推荐