2014-10-31 68 views
3

我正在绘制一系列使用matplotlib的热图。没有共享的Y轴,它可以正常工作。尽管我尝试和分享y轴,但我遇到了一个问题。 x轴限制看起来已经受到损坏。matplotlib imshow subplots sharey break x limits

考虑以下MWE:

import matplotlib 
print matplotlib.__version__ # prints "1.4.2" 

import matplotlib.pyplot as plt 

data = [[1,2,3], 
     [4,5,6], 
     [7,8,9], 
     [10,11,12]] 

nrows, ncols = 1, 4 
fig, axes = plt.subplots(nrows, ncols, sharey=True) 

for j in range(ncols): 
    xs = axes[j] 

    # seems to have no impact when sharey=True 
    #xs.set_xlim(-0.5, 2.5) 

    xs.imshow(data, interpolation='none') 
plt.show() 

这样做的不正确的输出是这样的:

Incorrect output with incorrect x limits

而只是在正确的输出变化sharey=Truesharey=False结果(所不同的是我想要y轴共享当然,现在不是):

Correct output with correct x limits

有没有办法解决这个问题?

回答

0

here以答案:

ax.set_adjustable('box-forced') 

所以:

for j in range(ncols): 
    xs = axes[j] 
    xs.set_adjustable('box-forced') 
    xs.imshow(data, interpolation='none') 

看来,这是故意的行为,你需要指定这个调和的分歧imshow()的行为方式上一个单一的情节,以及它是如何在一个次要情节上。