如何在 Matplotlib 中仅绘制表格? [英] How do I plot only a table in Matplotlib?
本文介绍了如何在 Matplotlib 中仅绘制表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以只用 matplotlib 绘制表格?如果我取消注释该行
plt.bar(index, data[row], bar_width, bottom=y_offset, color=colors[row])
这个例子的
然后您可以根据需要自由调整轴的位置.
Is it possible to draw only a table with matplotlib? If I uncomment the line
plt.bar(index, 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).
解决方案
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')
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")
axs[0].axis('tight')
axs[0].axis('off')
the_table = axs[0].table(cellText=clust_data,colLabels=collabel,loc='center')
axs[1].plot(clust_data[:,0],clust_data[:,1])
plt.show()
which looks like this,
You are then free to adjust the locations of the axis as required.
这篇关于如何在 Matplotlib 中仅绘制表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文