Matplotlib 表落在绘图区域之外

编程入门 行业动态 更新时间:2024-10-11 23:22:37
本文介绍了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 表落在绘图区域之外

本文发布于:2023-07-18 15:44:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1146352.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:落在   区域   Matplotlib

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!