【发布时间】:2019-04-30 09:59:58
【问题描述】:
我没有在这个方向找到任何东西,但如果我错了,请告诉我。
对于来自 seaborn 的jointgrid 方法和jointplot 方法都提出了这个问题,因为到目前为止它们都为我提供了相同的基本结果。但是,如果一种方法对以下问题更好,那没问题。到目前为止,这是我的联合图示例:
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
df=pd.DataFrame(np.random.rand(100,2),columns=['x','y'])
fig=sns.jointplot(x=df['x'],y=df['y'])
fig=fig.plot_joint(plt.scatter)
fig=fig.plot_marginals(sns.distplot,kde=False)
导致
现在我想用文字评论 x 和 y 轴上的分布图形。最后,在每个条形端上方应该有这个箱的总分布的百分比。但我不知道如何连接它。
使用普通的 distplot 我的代码看起来像这样。
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
df=pd.DataFrame(np.random.rand(100,2),columns=['x','y'])
total = float(len(df['x']))
ax=sns.distplot(df['x'],kde=False)
for p in ax.patches:
height = p.get_height()
print(p)
ax.text(p.get_x()+p.get_width()/2.,
height,
'{:1.0f}'.format((height/total)*100),
ha="center")
但是如何在jointplot的分布图上获得注释呢?
【问题讨论】:
标签: python matplotlib plot annotations seaborn