0
我正在绘制一个矩阵,如下所示,并且图例一遍又一遍地重复。我试过使用numpoints = 1,这似乎没有任何作用。任何提示?Python - 图例值重复
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib
%matplotlib inline
matplotlib.rcParams['figure.figsize'] = (10, 8) # set default figure size, 8in by 6inimport numpy as np
data = pd.read_csv('data/assg-03-data.csv', names=['exam1', 'exam2', 'admitted'])
x = data[['exam1', 'exam2']].as_matrix()
y = data.admitted.as_matrix()
# plot the visualization of the exam scores here
no_admit = np.where(y == 0)
admit = np.where(y == 1)
from pylab import *
# plot the example figure
plt.figure()
# plot the points in our two categories, y=0 and y=1, using markers to indicated
# the category or output
plt.plot(x[no_admit,0], x[no_admit,1],'yo', label = 'Not admitted', markersize=8, markeredgewidth=1)
plt.plot(x[admit,0], x[admit,1], 'r^', label = 'Admitted', markersize=8, markeredgewidth=1)
# add some labels and titles
plt.xlabel('$Exam 1 score$')
plt.ylabel('$Exam 2 score$')
plt.title('Admit/No Admit as a function of Exam Scores')
plt.legend()
这并不奇怪,因为你绘制多个数据集(线)每次;他们恰好是相同的颜色和符号。 – Evert
您可能可以绘制每种类型的一个数据集,为这些数据集分配一个标签,并为每种类型绘制没有标签的剩余数据集。当“admit”或“no_admit”为空或仅对第一个数据集有效时,这可能会出现问题。 – Evert