【问题标题】:Matplotlib table falls outside plot areaMatplotlib 表位于绘图区域之外
【发布时间】:2015-01-13 18:50:47
【问题描述】:

我在使用Matplotlib 的地块中有一张桌子,桌子溢出了地块区域。有没有办法让这种情况不会发生,也许有一个偏移量或类似的东西?

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

【问题讨论】:

  • 检查 plt.table 是否有 kwarg 调用 bbox_to_anchor。如果是这样,那么就像plt.legend 一样,您将能够指定表格的(锚点)位置。

标签: python python-2.7 matplotlib


【解决方案1】:

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

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

这是table对应的documentationbbox对应的@。

【讨论】:

  • 这让我可以移动它,但是这些点是从什么偏移的?
  • 添加了文档链接。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-10
  • 2015-11-10
  • 1970-01-01
相关资源
最近更新 更多