假設我們有一個熱力圖,如下所示
使用代碼進行構建
import string
import numpy as np
from matplotlib import pyplot as plt
label=list(string.ascii_uppercase)
mdata = np.random.randn(3, len(標簽), len(標簽)
data = mdata[0, :, :]
data=np.tril(data,-1)
fig, ax = plt.subplots()
heatmap = ax.pcolor(data, cmap=plt.cm.Blues)
plt.show()
無論是使用Matplotlib、Seaborn還是其他軟體包,都可以像下面這樣渲染成等距的 對齊,如下所示。
uj5u.com熱心網友回復:
PS:為了獲得完整的矩形,需要將np.indices的子陣列做成1D:
import numpy as np
import matplotlib.pyplot as plt
ax = plt.figure().add_subplot(projection='3d')
N =26
data = np.random.randn(3, N, N)
for i, (plane, cmap) in enumerate(zip(資料。['Reds'/span>, 'Greens'/span>, 'Blues'/span>])。
indices = np.indices((N,N))
norm = plt.Normalize(plane.min(), plane.max()
ax.bar(left=indices[0].ravel(), bottom=indices[1].ravel(), height=0.9,
zs=i, zdir='y'。
color=plt.get_cmap(cmap)(norm(plane).ravel() ))
plt.show()
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/312403.html
標籤:
上一篇:如何在sklearn的部分依賴性圖中洗掉十位數的標記?
下一篇:在Python中繪制矩陣圖



