Python 在matplotlib中制作表格

Python 在matplotlib中制作表格,python,matplotlib,datatable,Python,Matplotlib,Datatable,我试图用一组数据创建一个只有两列的表。以下是以下数据: data = [[ 66386, 174296, 75131, 577908, 32015], [ 58230, 381139, 78045, 99308, 160454], [ 89135, 80552, 152558, 497981, 603535], [ 78415, 81858, 150656, 193263, 69638], [139361, 331509, 343164, 78138

我试图用一组数据创建一个只有两列的表。以下是以下数据:

data = [[ 66386, 174296,  75131, 577908,  32015],
    [ 58230, 381139,  78045,  99308, 160454],
    [ 89135,  80552, 152558, 497981, 603535],
    [ 78415,  81858, 150656, 193263,  69638],
    [139361, 331509, 343164, 781380,  52269]]
我只想显示数据的第一列,这样我就可以看到如下所示的表:

下面是我尝试使用的代码片段:

columns = ('Freeze', 'Wind', 'Flood', 'Quake', 'Hail')
rows = ['%d year' % x for x in (100, 50, 20, 10, 5)]


# Get some pastel shades for the colors
colors = plt.cm.BuPu(np.linspace(0, 0.5, len(rows)))
n_rows = len(data)


# Initialize the vertical-offset for the stacked bar chart.
y_offset = np.zeros(len(columns))

# Plot bars and create text labels for the table
cell_text = []
for row in range(n_rows):
    y_offset = data[row]
    cell_text.append(['%1.1f' % (x / 1000.0) for x in y_offset])
# Reverse colors and text labels to display the last value at the top.
colors = colors[::-1]


 the_table = plt.table(cellText=cell_text,
                      rowLabels=rows,
                      rowColours=colors,
                      colLabels=columns,
                      loc='center')

如何调整此代码以获得所需的结果?

例如在列中添加属性“year”

columns = ('year','Freeze', 'Wind', 'Flood', 'Quake', 'Hail')
rows = ['%d year' % x for x in (100, 50, 20, 10, 5)]


# Get some pastel shades for the colors
colors = plt.cm.BuPu(np.linspace(0, 0.5, len(rows)))
n_rows = len(data)


# Initialize the vertical-offset for the stacked bar chart.
y_offset = np.zeros(len(columns))

# Plot bars and create text labels for the table
cell_text = []
for row in range(n_rows):
    y_offset = data[row]
    cell_text.append(['%1.1f' % (x / 1000.0) for x in y_offset])
# Reverse colors and text labels to display the last value at the top.
colors = colors[::-1]


 the_table = plt.table(cellText=cell_text,
                      rowLabels=rows,
                      rowColours=colors,
                      colLabels=columns,
                      loc='center')