Aim: To make a matplotlib.pyplot.table
opaque, so that the major and minor grid lines of a background plot do not appear within the foreground table.
Problem: I could not operate either matplotlib.pyplot.table
kwarg alpha
or matplotlib.artist.Artist.set_alpha
function correctly to change the transparency of a table plotted within a plot.
MWE: Please consider the following code example given as an answer for the question: How can I place a table on a plot in Matplotlib?
import matplotlib.pylab as plt
plt.figure()
ax=plt.gca()
plt.grid('on', linestyle='--')
y=[1,2,3,4,5,4,3,2,1,1,1,1,1,1,1,1]
col_labels=['col1','col2','col3']
row_labels=['row1','row2','row3']
table_vals=[[11,12,13],[21,22,23],[31,32,33]]
#
the_table = plt.table(cellText=table_vals,
colWidths = [0.1]*3,
rowLabels=row_labels,
colLabels=col_labels,
loc='center right')
plt.plot(y)
plt.show()
which produces the following:
Attempts:
I tried to get rid of the background grid lines within the table by adding alpha
keyword into plt.table
:
the_table = plt.table(cellText=table_vals,
colWidths = [0.1]*3,
rowLabels=row_labels,
colLabels=col_labels,
loc='center right',
alpha=1.0)
and then by calling set_alpha
:
the_table.set_alpha(1.0)
None of them resolved the issue or raised an error.