这里 首先要理解python的引用符 “=” 的用法, pyplot.subplots() 会返回两个对象,画板 fig 与 坐标轴ax。我们可以使用一个变量去接收这两个对象,也可以使用两个变量分别接收。
fig,ax= pyplot.subplots() 这个代码就是使用两个变量去分别接收两个变量。
from sklearn.datasets import make_moons
feature,target = make_moons(n_samples=100,noise=0.05)
from matplotlib import pyplot
from pandas import DataFrame
df = DataFrame(dict(x=feature[:,0],y=feature[:,1],label=target))
colors={0:'red',1:'blue'}
fig,ax= pyplot.subplots()
grouped = df.groupby('label')
for key,group in grouped:
group.plot(ax=ax,kind='scatter',x='x',y='y',label=key,color=colors[key])
pyplot.show()
df = DataFrame(dict(x=feature[:,0],y=feature[:,1],label=target))
为什么要先做成字典然后用dataframe?做城字典的意义是什么呢?
colors={0:'red',1:'blue'}
为什么要用大括号?
feature,target = make_moons(n_samples=100,noise=0.05)
target 是指代什么值?
fig,ax= pyplot.subplots()
这一句有什么用,尤其是后面没有出现 fig