1
3x3の例の赤い線のように、さまざまな数のサブプロットからなる図に線を描きたい。 matplotlibでこれをどうすればできますか?matplotlibのサブプロット行列の図を通って線を描く
このコードは、基本的に、4Dの例の多次元データ(scatter matrix plotの右上半分)の2D投影の配列です。ここ
from matplotlib import pyplot as plt
import numpy as np
data = np.random.random_sample((10,4))
labels = ['p1','p2','p3','p4']
fig, axarr = plt.subplots(3,3, sharex='col', sharey='row')
# Iterate over rows of subplots array
for row in range(axarr.shape[0]):
i = row # data index corresponds to row index
# Iterate over columns of subplots array
for col in range(axarr.shape[1]):
j = col+1 # data index corresponds to column index +1
# Do what's needed in lower-left half of array and leave
if row>col:
if col==0:
axarr[row,col].set_ylabel(labels[i],labelpad=5)
axarr[row,col].spines['left'].set_visible(False)
axarr[row,col].spines['right'].set_visible(False)
axarr[row,col].spines['bottom'].set_visible(False)
axarr[row,col].spines['top'].set_visible(False)
axarr[row,col].xaxis.set_ticks_position('none')
axarr[row,col].yaxis.set_ticks_position('none')
axarr[row,col].tick_params(labelleft=False)
axarr[row,col].tick_params(labelbottom=False)
continue
# Proceed with upper-right half of array
axarr[row,col].scatter(data[:,i],data[:,j], s=4)
axarr[row,col].tick_params(labelleft=False)
axarr[row,col].tick_params(labelbottom=False)
if row==0:
axarr[row,col].set_xlabel(labels[j],labelpad=5)
axarr[row,col].xaxis.set_label_position('top')
if col==0:
axarr[row,col].set_ylabel(labels[i],labelpad=5)
axarr[row,col].yaxis.set_label_position('left')
これは完璧に機能します。ありがとう!あなたのコードでは、コマンドを使っていくつかの詳細をパーソナライズすることもできます。 – Daniel