I have two python plot functions:
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
And second function is:
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
And i am calling both :
#####PLOT ######
ax = plotData(df)
ax = plot_boundry(opt_theta, x)
I get 2 separate plots:


I got 2 separate picture.How Do I add two plot into one. Both the plot should be one plot.
It depends what you want exactly:
If you want the two figures overlayed, then you can call hold(True) after the first, then plot the second, then call hold(False).
If you want the two figures in a single figure, but side by side (or one over the other), then you can use subplot. E.g., call subplot(2, 1, 1) before plotting the first, then subplot(2, 1, 2) before the second.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With