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
MatPlotLib with Python Convert the image from one color space to another. To remove grid lines, use ax. grid(False).
try this:
table.set_zorder(100)
from docs:
Artists with lower zorder values are drawn first.
So a high zorder will bring up the artist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With