【发布时间】:2020-04-25 15:06:34
【问题描述】:
我刚刚使用以下代码绘制了 2 个子图:
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(8,4))
ax1 = fig.add_subplot(121)
ax1.set_xlabel('Credit_History')
ax1.set_ylabel('Count of Applicants')
ax1.set_title("Applicants by Credit_History")
temp1.plot(kind='bar')
ax2 = fig.add_subplot(122)
temp2.plot(kind='bar')
ax2.set_xlabel('Credit_History')
ax2.set_ylabel('Probability of getting loan')
ax2.set_title("Probability of getting loan by credit history")
我得到以下输出
我得到了 3 个地块,即我想要的 2 个子地块,但是第二个地块是空的,上面有描述的标题。第三个在这两个之下,带有没有标题的 temp2 条。
我想要的是两个并排的子图,并带有所描述的标题。想知道我做错了什么吗?
【问题讨论】:
-
检查matplotlib.org/3.1.1/gallery/subplots_axes_and_figures/…。尽管给定的代码适用于垂直相邻的子图,但据说它也可以应用于水平相邻的子图。
标签: python matplotlib subplot