(x1、y1)、.....(x8、y8)のように(x、y)の8つの異なるペアがあり、最初のサブプロットが示す4つのサブプロット(すべて散布図)のプロットが必要です(x1 、y1)と(x2、y2)、2番目のサブプロットは(x3、y3)と(x4、y4)などを示します。次のコードを使用しましたが、2つの問題があります。
コードは次のとおりです。
import matplotlib.pyplot as plt
fig, ax = plt.subplots(2, 2,figsize=(12,12))
ax[0,0] = plt.scatter(x1,y1,color='red', marker = ".")#,order=order)
ax[0,0] = plt.scatter(x2,y2,color='blue', marker = ".")#,order=order)
ax[0,1] = plt.scatter(x3,y3,color='red', marker = ".")#,order=order)
ax[0,1] = plt.scatter(x4,y4,color='blue', marker = ".")#,order=order)
ax[1,0] = plt.scatter(x5,y5,color='red', marker = ".")#,order=order)
ax[1,0] = plt.scatter(x6,y6,color='red', marker = ".")#,order=order)
ax[1,1] = plt.scatter(x7,y7,color='red', marker = ".")#,order=order)
ax[1,1] = plt.scatter(x8,y8,color='red', marker = ".")#,order=order)
どんな助けでも大歓迎です。
問題は、サブプロットオブジェクト(fig
、を介してサブプロットにアクセスするax[i,j]
)を宣言ax[i,j]
し、通常のplt.scatter
オブジェクトを割り当ててアクセス変数を上書きしていたことです。
それがプログラムに同じサブプロット内のすべてのペアをプロットさせた理由を説明することはできませんが(それは機能するはずです)、それにもかかわらず、を使用ax[i,j].scatter()
すると問題が修正されるはずです:
import matplotlib.pyplot as plt
fig, ax = plt.subplots(2, 2,figsize=(12,12))
ax[0,0].scatter(x1,y1,color='red', marker = ".")#,order=order)
ax[0,0].scatter(x2,y2,color='blue', marker = ".")#,order=order)
ax[0,1].scatter(x3,y3,color='red', marker = ".")#,order=order)
ax[0,1].scatter(x4,y4,color='blue', marker = ".")#,order=order)
ax[1,0].scatter(x5,y5,color='red', marker = ".")#,order=order)
ax[1,0].scatter(x6,y6,color='red', marker = ".")#,order=order)
ax[1,1].scatter(x7,y7,color='red', marker = ".")#,order=order)
ax[1,1].scatter(x8,y8,color='red', marker = ".")#,order=order)
(これにより、set_xlabel
属性エラーも修正されるはずです)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加