我有兩個Python情節功能:Python的 - 兩個人物在一個情節
def plotData(data):
fig, ax = plt.subplots()
results_accepted = data[data['accepted'] == 1]
results_rejected = data[data['accepted'] == 0]
ax.scatter(results_accepted['exam1'], results_accepted['exam2'], marker='+', c='b', s=40)
ax.scatter(results_rejected['exam1'], results_rejected['exam2'], marker='o', c='r', s=30)
ax.set_xlabel('Exam 1 score')
ax.set_ylabel('Exam 2 score')
return ax
而第二個功能是:
def plot_boundry(theta,x):
"""
"""
plt.figure(1)
px = np.array([x[:, 1].min() - 2, x[:, 1].max() + 2])
py = (-1/theta[2]) * (theta[1] * px + theta[0])
fig, ax = plt.subplots()
ax.plot(px, py)
return ax
,我打電話都:
#####PLOT ######
ax = plotData(df)
ax = plot_boundry(opt_theta, x)
我得到了2張獨立的照片。我如何將兩張圖添加到一張。 這兩個情節應該是一個情節。
只需傳遞從'plotData'返回到'plot_boundary'的'ax'並將其用於'plot'。或者在函數之外創建'ax'並將它傳遞給兩者。 – AChampion
在傳遞完成之後,要改變的地方 – Aman
使用'ax'代替'fig,ax = plt.subplots()' – AChampion