在Seaborn Jointplot上绘制对角线(相等的线)

Spi*_*uce 12 python matplotlib seaborn

我正在使用seaborn jointplot进行散点图绘制,但我似乎无法得到一条简单的对角线...我正在得到一个AttributeError: 'JointGrid' object has no attribute 'get_xlim'.有没有人知道使用Seaborn的解决方法?

这是我的代码(标题也没有出现!给出了什么):

ax = sns.jointplot(x="Av Tomato-meter", y="Av Audience Score", data=director_combined_ratings, stat_func = None, 
                   size = 8, xlim=(0,100), ylim=(0,100))

ax.plot(ax.get_xlim(), ax.get_ylim(), ls="--", c=".3") #this is the error line.

ax.title = "Average Tomato-meter vs Audience Score for Directors with over 10 Movies"
Run Code Online (Sandbox Code Playgroud)

在此先感谢大家.

cph*_*wis 20

错误是一个有用的暗示:一个JointPlot是子图的集合,你必须找到特定的斧头来绘制.修改Seaborn示例:

import numpy as np
import pandas as pd
import seaborn as sns
from matplotlib.pyplot import show
sns.set(style="white")

# Generate a random correlated bivariate dataset
rs = np.random.RandomState(5)
mean = [0, 0]
cov = [(2, .25), (.5, 1)] # make it asymmetric as a better test of x=y line
x1, x2 = rs.multivariate_normal(mean, cov, 500).T
x1 = pd.Series(x1, name="$X_1$")
x2 = pd.Series(x2, name="$X_2$")

# Show the joint distribution using kernel density estimation
g = sns.jointplot(x1, x2, kind="kde", height=7, space=0)

x0, x1 = g.ax_joint.get_xlim()
y0, y1 = g.ax_joint.get_ylim()
lims = [max(x0, y0), min(x1, y1)]
g.ax_joint.plot(lims, lims, ':k')    
show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我在翻译中想到了这一点:dir(g)那么g.plot?,g.plot_joint?- 那些是绘制特定于联合图的功能 - 还有什么?- dir(g.ax_joint); 啊哈set_ylim,等等