使用matplotlib.pyplot绘制表内列的列表

时间:2018-04-19 06:08:23

标签: python matplotlib

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

    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

1 个答案:

答案 0 :(得分:0)

试试这个。

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()

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