使用 matplotlib.pyplot 在表中按列绘制列表



我有两个列表,需要根据它们的列标题绘制为表格:

    import matplotlib.pyplot as plt
    columnheaders=('Question Text', 'Answer Status')
    data_list_1=['hi','name pleas','how are you']
    data_list_2=['answered','notanswered','answered']
    **##the_table=ax.table(cellText=data_list,colLabels=columns,)**
    ax.axis("off")
    the_table.set_fontsize(14)
    the_table.scale(1.5, 1.5)
    plt.show()

如何将data_list_1和data_list_2传递给 ax.table(( 函数,以便获得以下格式的表:

Question text           answer status
hi                          answered
name please                 not answered
how are you                 answered

试试这个。

import matplotlib.pyplot as plt
columnheaders=['Question Text', 'Answer Status']
data_list_1=['hi','name pleas','how are you']
data_list_2=['answered','notanswered','answered']
l = [data_list_1, data_list_2]
l = list(map(list, zip(*l)))
the_table=plt.table(cellText=l,loc='top', colLabels = columnheaders, cellLoc='center')
plt.axis("off")
the_table.set_fontsize(14)
the_table.scale(2, 7)
plt.show()

您需要以正确的格式获取数据

最新更新