Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Seaborn显示一个条形图而不是多个条形图_Python_Seaborn - Fatal编程技术网

Python Seaborn显示一个条形图而不是多个条形图

Python Seaborn显示一个条形图而不是多个条形图,python,seaborn,Python,Seaborn,我的代码看起来像 ylst = [.1,.2,.3,.4,.5,.6,.7,.8] xlst=["A","B","C","D","E","F","G","H"] with PdfPages('probs.pdf') as pdf_pages: for i in range(0,len(xlst), 2): ax=sns.barplot(xlst[i:i+2], ylst[i:i+2]) ax.axes.set_title('Which name', fon

我的代码看起来像

ylst = [.1,.2,.3,.4,.5,.6,.7,.8]
xlst=["A","B","C","D","E","F","G","H"]
with PdfPages('probs.pdf') as pdf_pages:
    for i in range(0,len(xlst), 2):
        ax=sns.barplot(xlst[i:i+2], ylst[i:i+2])
        ax.axes.set_title('Which name', fontsize=24,color="b",alpha=0.3)
        ax.set_ylabel("Probability (%)",size = 17,color="r",alpha=0.5)

        for p in ax.patches:
            ax.annotate(str(p.get_height()), (p.get_x() * 1.005, p.get_height() * 1.005))
        pdf_pages.savefig()
我想在一个2行2列的矩阵中绘制4个图。也就是说,左上角的绘图应该显示
A
B
,并带有值.1和.2。然后,左下或右上绘图应显示
C
D
,并带有值.3和.4。等等

然而,我得到的是:


如何修复此问题?

我已经测试过此功能:

import matplotlib.pyplot as plt, seaborn as sns
from matplotlib.backends.backend_pdf import PdfPages

ylst = [.1,.2,.3,.4,.5,.6,.7,.8]
xlst=["A","B","C","D","E","F","G","H"]
with PdfPages('probs.pdf') as pdf_pages:
    fig,((ax1,ax2),(ax3,ax4)) = plt.subplots(2,2)
    list_of_axes = (ax1,ax2,ax3,ax4)
    for i,j in zip(range(0,len(xlst), 2),list_of_axes):
        sns.barplot(xlst[i:i+2], ylst[i:i+2],ax=j)
        j.axes.set_title('Which name', fontsize=24,color="b",alpha=0.3)
        j.set_ylabel("Probability (%)",size = 17,color="r",alpha=0.5)

        for p in j.patches:
            j.annotate(str(p.get_height()), (p.get_x() * 1.005, p.get_height() * 1.005))
    pdf_pages.savefig()
    plt.close()
我刚刚为每个子批次分配了一个轴,并将
.savefig()
移动到循环外部