0

並列ループを使用して、いくつかのカーネル プロットを作成しようとしています。棒グラフを使用するとループが機能しますが、カーネル プロットを使用するとうまくいきません。私はPythonが初めてなので、かなり明白なものが欠けていると思います-何か提案はありますか? ありがとう!

ああ、そしてlen(schools) = 3

#the kernel plot
fig = plt.figure(facecolor='white')
gs1 = GridSpec(1,len(schools))
sp1 = [plt.subplot(gs1[0,i]) for i in range(len(schools))]
colors = ["red", "blue", "green"]
schools2 = [[data1....],[data2....],[data3......]]
for ax, i in zip(sp1, range(len(schools))):
    ax = sns.kdeplot(schools2[i], bw=.5, color = colors[i], lw=1.8, vertical=True, alpha=.5)

.

#the bar plot
fig = plt.figure(facecolor='white')
gs1 = GridSpec(1,len(schools))
sp1 = [plt.subplot(gs1[0,i]) for i in range(len(schools))]
colors = ["red", "blue", "green"]
test = [1,2,3]
for ax, i in zip(sp1, range(3)):
    ax.bar(1, test[i], color = colors[i])
4

1 に答える 1

1

matplotlib プロット関数を直接使用する場合、たとえばplt.bar(...)ax.bar(...). 前者の場合、プロットは「現在アクティブな」軸に描画されますが、後者の場合、プロットは常にax変数にバインドされた軸に移動します。

同様に、seaborn プロット関数を使用すると、たとえばsns.kdeplot(...)、「現在アクティブな」軸にプロットされます。matplotlib オブジェクト指向インターフェイスを使用してプロットが終了する場所を制御するために、ほとんどの [1] seaborn 関数はaxパラメーターを取り、これに Axes オブジェクトを渡しますsns.kdeplot(..., ax=ax)

  1. kdeplot、 、および特定の Axes にプロットする他の多くの関数と、図全体の関数であり、特定の Axes または Figure に割り当てることができない 、 などのviolinplotより複雑な関数との間には区別があるため、ほとんどと言います。 . 前者の関数はいずれも引数を取ります。lmplotfactorplotax
于 2014-05-22T20:13:35.923 に答える