python - 如何在 jupyter + pandas 中的每个 scatter_matrix 上添加标题

标签 python pandas matplotlib jupyter

因此,我在不同时间对数据集进行了多次采样。 对于每个采样,我想绘制一个散点矩阵,每个散点矩阵都应将采样时间作为标题。

问题是 pandas.tools.plotting.scatter_matrix 没有参数“title”

当我尝试在绘制图形之前打印()标题时,它会在绘制图形之前打印所有标题。

for qid in qids:
    date = db[collection].find_one({ "querySummary.qid": qid }, {"querySummary.date":1})["querySummary"]["date"].isoformat()
    print(date) # does not provide the desired result
    cursor = db[collection].find({ "querySummary.qid": qid })
    cols = ["resultNum", "col2", "col3", "col4"] # list of columns labels
    rows = [] # will be populated below
    for result in cursor:
        rows.append([result["resultNum"], result["col2"], result["col3"], result["col4"]])
    df = pd.DataFrame(rows, columns=cols);
    scatter_matrix(df, alpha=0.3, figsize=(16,16), diagonal='kde', marker=date)

通过运行代码,在最终绘制第一个 scatter_matrix 之前,标题全部打印出来:

Result not as expected

有什么想法吗?

最佳答案

在这种情况下,您不能使用 print(date)。相反,请为每个 scatter_matrix 尝试 plt.suptitle(date),如下所示。

for qid in qids:
    date = db[collection].find_one({ "querySummary.qid": qid }, {"querySummary.date":1})["querySummary"]["date"].isoformat()
    cursor = db[collection].find({ "querySummary.qid": qid })
    cols = ["resultNum", "col2", "col3", "col4"] # list of columns labels
    rows = [] # will be populated below

    for result in cursor:
        rows.append([result["resultNum"], result["col2"], result["col3"], result["col4"]])
    df = pd.DataFrame(rows, columns=cols);
    scatter_matrix(df, alpha=0.3, figsize=(16,16), diagonal='kde', marker='o')

    plt.suptitle(date)

关于python - 如何在 jupyter + pandas 中的每个 scatter_matrix 上添加标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37128732/

相关文章:

python - 突出显示 matplotlib 矩阵上的某些点

python - Python 中的 "for ... in"循环会增加空间复杂度吗?

python - 有没有办法让这变得更容易?

python - 如何用条件替换pandas列值?

python - matplotlib 将带有 stddev 轴的正态分布叠加到另一个图上

python - 在 matplotlib 中用两个 y 轴格式化 x 轴标签(条形图和线图)

php - 如何创建 URL 提取器,如 facebook 共享

Python。 nwise numpy 数组迭代

python - 构建一个python项目

python - 查找月中两个日期时间之间的差异