Grid appearing inside table in matplotlib/pyplot graph

Viewed 1063

I'm trying to add a data summary table to a plot I'm creating like so:

import matplotlib.pyplot as plt

plt.figure()
plt.plot([0,2], [0,2])
plt.grid('on')

values = [[0,1],[2,3]]
rowLabels = ['row1', 'row2']
colLabels = ['col1', 'col2']

table = plt.table(cellText=values, colWidths=[0.1]*3, rowLabels = rowLabels, 
      colLabels=colLabels, loc = 'center right')

But where the grid and the table overlap the grid is still visible which makes the table hard to read.

So I tried adding this code to set the background of the table cells to white and opaque like so:

cells = table.get_celld()

for cell in cells:
    cells[cell].set_facecolor('white')
    cells[cell].set_alpha(1)

But it doesn't change. If I use a color other than white I can see it is setting the cell color but the grid is still visible, which makes me think that the grid is being drawn on top of the table rather than behind it.

Anybody know of an approach to get the table on a graph with a grid but keep the grid out of the table?

Thanks!

Using current latest matplotlib: version 1.3.1

1 Answers
Related