我正在尝试在带有边缘轴的密度图旁边绘制一个颜色条。它确实绘制了颜色条,但不幸的是不是在侧面。到目前为止,这就是尝试过的:
sns.jointplot(x,y, data=df3, kind="kde", color="skyblue", legend=True, cbar=True,
xlim=[-10,40], ylim=[900,1040])
Run Code Online (Sandbox Code Playgroud)
它看起来像这样:
我也尝试过这个:
from matplotlib import pyplot as plt
import seaborn as sns
import numpy as np
kdeplot = sns.jointplot(x=tumg, y=pumg, kind="kde")
plt.subplots_adjust(left=0.2, right=0.8, top=0.8, bottom=0.2)
cbar_ax = kdeplot.fig.add_axes([.85, .25, .05, .4])
plt.colorbar(cax=cbar_ax)
plt.show()
Run Code Online (Sandbox Code Playgroud)
但使用第二个选项时,我收到运行时错误:
No mappable was found to use for colorbar creation.
First define a mappable such as an image (with imshow) or a contour set (with contourf).
有谁知道如何解决这个问题?
matplotlib.pyplot.scatter()
有一个facecolors=None
参数将使数据点看起来内部是空心的。如何获得相同的外观seaborn.jointplot()
?
在早期版本的seaborn中也发现了相同的论点,但由于某种原因在最新版本(0.11)中被删除。
如何去掉剧情中的图例seaborn.JoingGrid
?
参考代码如下:
import matplotlib.pyplot as plt
import seaborn as sns
penguins = sns.load_dataset("penguins")
g = sns.JointGrid(data=penguins, x="bill_length_mm", y="bill_depth_mm", hue="species")
g.plot_joint(sns.scatterplot)
sns.boxplot(data=penguins, x=g.hue, y=g.y, ax=g.ax_marg_y)
sns.boxplot(data=penguins, y=g.hue, x=g.x, ax=g.ax_marg_x)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下已知适用于其他seaborn地块的方法,但在jointplot上失败了:
plt.legend([],[], frameon=False)
g._legend.remove()
Run Code Online (Sandbox Code Playgroud) 在最新的seaborn版本发布之前,我能够使用以下内容用pearson Rho来注释我的情节。
使用最新版本,我无法找到一种方法来执行与#ax.annotate(stats.pearsonr)
抛出错误相同的操作。
import matplotlib as mpl
import scipy.stats as stat
import matplotlib.pyplot as plt
import pandas as pd, numpy as np
import scipy.stats as stats
import seaborn as sns
X = np.random.rand(10,2)
df = pd.DataFrame(X, columns=['v1', 'v2'])
a = df.v1.values
b = a*2 + a**5
print("The Rho is {}".format(np.corrcoef(a,b)[0][1]))
ax = sns.jointplot(a, b, kind='reg',color='royalblue')
#ax.annotate(stats.pearsonr)
ax.ax_joint.scatter(a,b)
ax.set_axis_labels(xlabel='a', ylabel='b', size=15)
plt.tight_layout()
plt.show()
Run Code Online (Sandbox Code Playgroud)
我无法再得到的旧输出:
如何缩放seaborn联合图的边际kdeplot?
假设我们有 1000 个类型“a”的数据、100 个类型“b”的数据和“100”个类型“c”的数据。
在这种情况下,边际 kdeplot 的尺度看起来并不相同,因为分类数据的大小完全不同。
我如何使这些相同?
我制作了一个玩具脚本,如下所示:
import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib.pylab as plt
ax, ay = 1 * np.random.randn(1000) + 2, 1 * np.random.randn(1000) + 2
bx, by = 1 * np.random.randn(100) + 3, 1 * np.random.randn(100) + 3
cx, cy = 1 * np.random.randn(100) + 4, 1 * np.random.randn(100) + 4
a = [{'x': x, 'y': y, 'kind': 'a'} for x, y in zip(ax, ay)]
b …
Run Code Online (Sandbox Code Playgroud) 我试图通过以下方式绘制:
g = sns.jointplot(x = etas, y = vs, marginal_kws=dict(bins=100), space = 0)
g.ax_joint.set_xscale('log')
g.ax_joint.set_yscale('log')
g.ax_joint.set_xlim(0.01)
g.ax_joint.set_ylim(0.01)
g.ax_joint.set_xlabel(r'$\eta$')
g.ax_joint.set_ylabel("V")
plt.savefig("simple_scatter_plot_Seanborn.png",figsize=(8,8), dpi=150)
Run Code Online (Sandbox Code Playgroud)
这给我留下了以下图像:
这不是我想要的。为什么最后要填充直方图?那里没有数据点,所以我不明白......
jointplot ×6
seaborn ×6
python ×5
matplotlib ×3
jointgrid ×2
colorbar ×1
kdeplot ×1
legend ×1
scaling ×1
scatter-plot ×1