snowflake snowflake - 1 year ago 376
Python Question

Matplotlib table only

Is it possible to draw only a table with matplotlib? If I uncomment the line, data[row], bar_width, bottom=y_offset, color=colors[row])

of this example code, the plot is still visible. I want to have a table on top of my (PyQt) window and underneath a plot (with some space in between).

Any help is very appreciated!

Answer Source

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,

Then adjusting the plot with,

plt.subplots_adjust(left=0.2, top=0.8)

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")
the_table = axs[0].table(cellText=clust_data,colLabels=collabel,loc='center')


which looks like this,

enter image description here

You are then free to adjust the locations of the axis as required.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download