如何在Matplotlib中仅绘制表? [英] How do I plot only a table in Matplotlib?

查看:2160
本文介绍了如何在Matplotlib中仅绘制表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用matplotlib绘制一张桌子?如果我取消注释该行

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])

在此示例代码中,该图仍然可见.我想在(PyQt)窗口上方和绘图下方(中间有一些空格)有一张桌子.

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).

推荐答案

如果您只想更改 example 并将表格放在顶部,然后您需要在表格声明中的loc='top'

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')

然后用调整图,

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()

看起来像这样

然后您可以根据需要需要来随意调整轴的位置.

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

这篇关于如何在Matplotlib中仅绘制表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆