因此,我在不同时间对数据集进行了多次采样。 对于每个采样,我想绘制一个散点矩阵,每个散点矩阵都应将采样时间作为标题。
问题是 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 之前,标题全部打印出来:
有什么想法吗?
最佳答案
在这种情况下,您不能使用 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/