我尝试播放视频中的图,但收到以下错误-ImportError:无法从“matplotlib. patches”导入名称“Patches”
ImportError
我的代码:
from colour import Color
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import matplotlib.patches as mpatches
from matplotlib.patches import Patches as mpatches
plt.figure(figsize=(12,5))
plt.scatter(X, Y, color='blue')
#DC
plt.scatter(X[0], Y[0],color='red', marker='D')
plt.annotate("DC",(X[0]-1,Y[0]-5.5))
#imprimir as rotas
for r in range(len(rotas)):
for n in range(len(rotas[r])-1):
i = rotas[r][n]
j = rotas[r][n+1]
plt.plot([X[i],X[j]], [Y[i],Y[j]], color=Color(r), alpha=0.4)
for r in range(len(temp_acum)):
for n in range(len(temp_acum[r])):
i = rotas[r][n]
plt.annotate('$q_{%d}=%d$ |$t_{%d}=%d$' %(i, q[i], i, temp_acum[r][n]), (X[i]+1,Y[i]))
patch = [mpatches.Patch(color=Color(n), label="Veiculo "+str(truck[n])+"|cap="+str(Q[truck[n]])) for n in range(len(truck))]
plt.legend(handles=patch,loc='best')
plt.xlabel('Distância X')
plt.ylabel('Distância Y')
plt.title('CVRPTW | Problema de Roteamento de Veículos com Janela de Tempos')
plt.show()
1条答案
按热度按时间ar7v8xwq1#
正如@马特在评论中所说:
是的,应该是
它是
Patch
而不是Patches
链接到文档https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html