我正在尝试在带有边缘轴的密度图旁边绘制一个颜色条。它确实绘制了颜色条,但不幸的是不是在侧面。到目前为止,这就是尝试过的:
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).
有谁知道如何解决这个问题?
我正在创建一个直方图(频率与计数),并且我想添加不同颜色的核密度估计线。我怎样才能做到这一点?例如我想改变颜色
sns.histplot(data=penguins, x="flipper_length_mm", kde=True)
示例取自https://seaborn.pydata.org/ generated/seaborn.histplot.html
我正在尝试使用 Seaborn 的 kdeplot 制作一个漂亮的自由能表面(热图)。我非常接近,但无法找到改变颜色条比例的方法。颜色条比例很重要,因为它应该表示地图上不同坐标处的能量差异。我需要知道如何按 缩放颜色条的值-(0.5961573)*log(x),其中x颜色条的值在哪里。然后我可能还需要从那里标准化颜色条,以便最大值为 0。
这是我目前拥有的:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import seaborn as sns
rs=[]
dihes=[]
with open(sys.argv[1], 'r') as f:
for line in f:
time,r,dihe = line.split()
rs.append(float(r))
dihes.append(float(dihe))
sns.set_style("white")
sns.kdeplot(rs, dihes, n_levels=25, cbar=True, cmap="Purples_d")
plt.show()
Run Code Online (Sandbox Code Playgroud)
这让我:

数组 rs 和 dihes 是简单的一维数组。
任何有关如何缩放颜色条(z 轴)的建议都会非常有帮助!
hue组的 aseaborn.kdeplot或seaborn.displotwithkind='kde'赋予不同的值linestyle?
strfor linestyle/ls,它适用于所有hue组。import seaborn as sns
import matplotlib.pyplot as plt
# load sample data
iris = sns.load_dataset("iris")
# convert data to long form
im = iris.melt(id_vars='species')
# axes-level plot works with 1 linestyle
fig = plt.figure(figsize=(6, 5))
p1 = sns.kdeplot(data=im, x='value', hue='variable', fill=True, ls='-.')
# figure-level plot works with 1 linestyle
p2 = sns.displot(kind='kde', data=im, x='value', hue='variable', fill=True, ls='-.')
Run Code Online (Sandbox Code Playgroud)
kdeplotdisplot