Reputation: 368
Is it possible to plot a table within specific subplot. Using the example below, I'd like the table to be inserted into ax1
. Rather than ax3
.
import matplotlib.pyplot as plt
import matplotlib as mpl
fig = plt.figure(figsize = (5,6))
grid = plt.GridSpec(3, 2, wspace = 0.4, hspace = 0.3)
gridsize = (3, 2)
ax1 = plt.subplot2grid(gridsize, (0, 0), colspan = 2, rowspan = 2)
ax2 = plt.subplot2grid(gridsize, (2, 0), colspan = 1, rowspan = 1)
ax3 = plt.subplot2grid(gridsize, (2, 1), colspan = 1, rowspan = 1)
ax1.set_xlim(0,10)
ax1.set_ylim(0,10)
xy = 5,5
Oval = mpl.patches.Circle(xy, color = 'blue', alpha = 0.2)
ax1.add_patch(Oval)
table = plt.table(cellText= [[''],['']],
colWidths = [0.2],
rowLabels=['row','row'],
colLabels=[''],
bbox = [0.3, 0.5, 0.2, 0.5])
Upvotes: 0
Views: 553
Reputation: 10320
You are looking for the matplotlib.axes.Axes.table
method, which allows you to add a table to a specific Axes
instance instead of to the 'current' instance as matplotlib.pyplot.table
does. The usage is identical.
table = ax1.table(cellText= [[''],['']],
colWidths = [0.2],
rowLabels=['row','row'],
colLabels=[''],
bbox = [0.3, 0.5, 0.2, 0.5])
Upvotes: 1