Matplotlib 表落在绘图区域之外 [英] Matplotlib table falls outside plot area

查看:78
本文介绍了Matplotlib 表落在绘图区域之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Matplotlib 的绘图中有一个表格,表格溢出绘图区域.有没有办法避免这种情况发生,也许是使用偏移量或类似的方法?

I have a table within a plot using Matplotlib and the table spills out past the plot area. Is there a way to make this not happen, perhaps with an offset or something similar?

import matplotlib.pylab as plt

plt.figure()
ax=plt.gca()

col_labels=['col1','col2','col3']
row_labels=['row1','row2','row3']
table_vals=[[11,12,13],[21,22,23],[31,32,33]]
the_table = plt.table(cellText=table_vals,
                  colWidths = [0.1]*3,
                  rowLabels=row_labels,
                  colLabels=col_labels,
                  loc='center left')
plt.text(12,3.4,'Table Title',size=8)


plt.show()

推荐答案

添加一个bbox参数,这样就可以控制准确的位置,例如:

Add a bbox parameter, in this way you can control the exact location, for example:

plt.table(cellText=table_vals,
                  colWidths = [0.1]*3,
                  rowLabels=row_labels,
                  colLabels=col_labels,
                  loc='center left',
                  bbox=[0.25, -0.5, 0.5, 0.3])

这是文档>表 bbox 的表.

Here is the corresponding documentation for table and the one for bbox.

这篇关于Matplotlib 表落在绘图区域之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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