How do I plot only a table in Matplotlib?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How do I plot only a table in Matplotlib in Python. So Here I am Explain to you all the possible Methods here.

How do I plot only a table in Matplotlib?

1. How do I plot only a table in Matplotlib?

Not sure if this is already answered, but if you want only a table in a figure window, then you can hide the axes:

2. plot only a table in Matplotlib

Not sure if this is already answered, but if you want only a table in a figure window, then you can hide the axes:

Method 1

If you just wanted to change the example and put the table at the top, then loc='top' in the table declaration is what you need,

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

A more flexible option is to put the table in its own axis using subplots,

import numpy as np
import matplotlib.pyplot as plt

fig, axs =plt.subplots(2,1)
clust_data = np.random.random((10,3))
collabel=("col 1", "col 2", "col 3")
axs.axis('tight')
axs.axis('off')
the_table = axs.table(cellText=clust_data,colLabels=collabel,loc='center')

axs.plot(clust_data[:,0],clust_data[:,1])
plt.show()

which looks like this,

Method 2

Not sure if this is already answered, but if you want only a table in a figure window, then you can hide the axes:

fig, ax = plt.subplots()

# Hide axes
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)

# Table from Ed Smith answer
clust_data = np.random.random((10,3))
collabel=("col 1", "col 2", "col 3")
ax.table(cellText=clust_data,colLabels=collabel,loc='center')

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.