在Seaborn Jointp上画对角线(等高线)

2024-05-14 19:55:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用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"

提前谢谢大家。


Tags: get绘制seabornaxattributeerrorscoremeteraudience
1条回答
网友
1楼 · 发布于 2024-05-14 19:55:40

这个错误是一个有用的提示:JointPlot是子块的集合,您必须找到要绘制到的特定ax。修改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()

enter image description here

我在一个解释器中发现了这个问题:dir(g),然后g.plot?g.plot_joint?——这些是特定于jointplot的绘图函数——还有什么?--dir(g.ax_joint);啊哈,还有set_ylim等等

相关问题 更多 >

    热门问题