作者:mobiledu2502906557 | 来源:互联网 | 2023-02-03 20:13
我试图使用matplotlib绘制热图,类似于plotly的热图。我能够通过matshow图的大小得到输出很小。下图是
是否有可能得到下图:
以下是我的代码:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
z = []
for _ in range(7):
new_row = []
for __ in range(180):
new_row.append(np.random.poisson())
z.append(list(new_row))
df1 = pd.DataFrame(np.array(z), columns=range(len(z[0])))
fig = plt.figure(figsize=(20,10))
ax = fig.add_subplot(111)
cax = ax.matshow(df1, interpolation='nearest', cmap='coolwarm')
fig.colorbar(cax)
ax.set_xticklabels([''] + list(df1.columns))
ax.set_yticklabels([''] + list(df1.index))
plt.show()
请帮助。
1> ImportanceOf..:
您可能要使用
ax.matshow(... , aspect="auto")
消除imshow
或方面方面的限制matshow
。