我正在尝试设置散点图中每个点的图例。我的主要问题是每个点的颜色与图例中的颜色不匹配。我做错了什么,我该如何纠正?
def scatter(self, indep, dep, labl):
x = self.df_input[indep]
y = self.df_input[dep]
random = np.random.RandomState(0)
colors = random.rand(len(labl)+1)
fig = plt.figure()
ax = fig.add_subplot(111)
for leg in labl:
ax.scatter(x, y, c=colors, cmap='gist_ncar', label=leg)
ax.legend()
ax.set_xlabel(indep)
ax.set_ylabel(dep)
ax.axis('tight')
plt.show()
翻过高山走不出你
犯罪嫌疑人X
随时随地看视频慕课网APP
相关分类