Tim*_*Tim 2 python numpy matplotlib
我在matplotlib中有一个热图,我想删除图中北部和东部的空白,如下图所示.
这是我用来生成图的代码:
# plotting
figsize=(50,20)
y,x = 1,2
fig, axarry = plt.subplots(y,x, figsize=figsize)
p = axarry[1].pcolormesh(copy_matrix.values)
# put the major ticks at the middle of each cell
axarry[1].set_xticks(np.arange(copy_matrix.shape[1])+0.5, minor=False)
axarry[1].set_yticks(np.arange(copy_matrix.shape[0])+0.5, minor=False)
axarry[1].set_title(file_name, fontweight='bold')
axarry[1].set_xticklabels(copy_matrix.columns, rotation=90)
axarry[1].set_yticklabels(copy_matrix.index)
fig.colorbar(p, ax=axarry[1])
Phylo.draw(tree, axes=axarry[0])
Run Code Online (Sandbox Code Playgroud)
最简单的方法是使用ax.axis('tight')
.
默认情况下,matplotlib会尝试为轴限制选择"偶数"数字.如果您希望将绘图缩放到数据的严格限制,请使用ax.axis('tight')
. ax.axis('image')
类似,但也会使你的"热图"的单元格成为正方形.
例如:
import numpy as np
import matplotlib.pyplot as plt
# Note the non-"even" size... (not a multiple of 2, 5, or 10)
data = np.random.random((73, 78))
fig, axes = plt.subplots(ncols=3)
for ax, title in zip(axes, ['Default', 'axis("tight")', 'axis("image")']):
ax.pcolormesh(data)
ax.set(title=title)
axes[1].axis('tight')
axes[2].axis('image')
plt.show()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2097 次 |
最近记录: |