1
我需要在Python中創建一個散佈矩陣。我嘗試過使用scatter_matrix,但我想只留下對角線上方的散點圖。熊貓scatter_matrix模擬函數對(lower.panel,upper.panel)
我真的開始(沒有遠),並且當列有名字(而不是默認數字)時我遇到了麻煩。
這裏是我的代碼:
import itertools
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
data=pd.DataFrame(np.random.randint(0,100,size=(10, 5)), columns=list('ABCDE')) #THE PROBLEM IS HERE - I WILL HAVE COLUMNS WITH NAMES
d = data.shape[1]
fig, axes = plt.subplots(nrows=d, ncols=d, sharex=True, sharey=True)
for i in range(d):
for j in range(d):
ax = axes[i,j]
if i == j:
ax.text(0.5, 0.5, "Diagonal", transform=ax.transAxes,
horizontalalignment='center', verticalalignment='center',
fontsize=16)
else:
ax.scatter(data[j], data[i], s=10)