将 seaborn 图形添加到子图中通常是通过在创建图形时传递 'ax'来完成的。例如:
sns.kdeplot(x, y, cmap=cmap, shade=True, cut=5, ax=ax)
Run Code Online (Sandbox Code Playgroud)
但是,此方法不适用于seaborn.palplot,它可视化 seaborn 调色板。我的目标是创建一个不同调色板的图形,用于可扩展的颜色比较和演示。此图像粗略地显示了我正在尝试创建的图 [源]。
一个可能相关的答案描述了一种创建 seaborn 图形并将轴复制到另一个图形的方法。我一直无法将这种方法应用于 palplot 图形,并且想知道是否有一种快速的方法可以将它们强制转换为现有图形。
这是我的最小工作示例,现在仍在生成单独的数字。
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
fig1 = plt.figure()
length, n_colors = 12, 50 # amount of subplots and colors per subplot
start_colors = np.linspace(0, 3, length)
for i, start_color in enumerate(start_colors):
ax = fig1.add_subplot(length, 1, i + 1)
colors = sns.cubehelix_palette(n_colors=n_colors, …
Run Code Online (Sandbox Code Playgroud)