[英]How to draw two stacked histograms side-by-side with Matplotlib/Seaborn
[英]How to get two subplots side-by-side in matplotlib?
我只是使用以下代码来绘制 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 条。
我想要的是两个子图并排与描述的标题。 想知道我做错了什么?
除非我将plt.show()
放在创建第二个轴实例和temp2.plot(kind='bar')
之间,否则我无法完全重现这一点。 如果您没有调用plt.show()
(或以其他方式清除缓冲区),您应该尝试
temp1.plot(kind='bar', ax=ax1)
temp2.plot(kind='bar', ax=ax2)
这应该正确使用两个生成的轴实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.