如何在图中显示方法的结果

时间:2015-07-24 20:45:01

标签: python pandas matplotlib

我尝试使用matplotlib创建数据分析报告。在其中,将进行多次绘图。设计是

|--------------------------------------------------------|
||--------------| |-------------------------------------||
||              | |                                     ||
||    Title     | |                                     ||
|| author name  | |          histograms                 ||
||              | |                                     ||
||              | |                                     ||
||--------------| |                                     ||
||--------------| |                                     ||
||              | |                                     ||
||  summary     | |                                     ||
||              | |                                     ||
||--------------| |-------------------------------------||
|--------------------------------------------------------|

在摘要部分中,我想显示pandas.DataFrame.describe()。我怎么能这样做?

在摘要之上,我想用我的姓名和日期显示标题。我怎么能这样做?

我知道import matplotlib.pyplot as mat并知道如何使用mat.subplot2grid()在指定区域放置特定的地图。但是,我不知道如何将一个函数的结果放在一个区域中,并在另一个区域创建自己的标题,如下所示:

|---------------------------------------------------------------------------|
||---------------------------------| |-------------------------------------||
||                                 | |                                     ||
|| Summary table for Capgemini     | |                                     ||
|| by Caren Van Der Lee            | |          histograms                 ||
||                                 | |                                     ||
||                                 | |                                     ||
||---------------------------------| |                                     ||
||---------------------------------| |                                     ||
||                                 | |                                     ||
||       summary  by               | |                                     ||
||  pandas.DataFrame.describe()    | |                                     ||
||---------------------------------| |-------------------------------------||
|---------------------------------------------------------------------------|

1 个答案:

答案 0 :(得分:0)

根据Amy Teegarden发布的链接,您可以将坐标和字符串传递给.figtext()方法以添加文字。

  

我不知道如何在一个区域中放置一个函数的结果,并在另一个区域创建自己的标题,如下所示:

我不知道该功能的结果是什么,但如果您可以将其转换为字符串,则可以使用.figtext()输出。

根据Amy Teegarden所说的例子:

import matplotlib.pyplot as plt

fig = plt.figure()
fig.suptitle('bold figure suptitle', fontsize=14, fontweight='bold')

ax = fig.add_subplot(111)
fig.subplots_adjust(top=0.85)
ax.set_title('Title goes here')
result = function(param1, param2, ...)
ax.figtext(3, 8, result)

您可以通过重载方法(如着色和粗体/斜体)为.figtext()指定更多自定义项。

我暂时没有在python中编码,所以这可能是在黑暗中拍摄的。

修改

pandas.DataFrame.describe()返回NDFrame object,可以作为数组访问(基于特定类型的多维)。 Here is a link显示了向matplotlib添加不同对象的示例,如果您决定以不同方式对其进行格式化。