Skip to content

make_axes_locatable broken with imshow plots that specify an extent and an aspect ratio #4282

Closed
@ngoldbaum

Description

@ngoldbaum

The following script and the image it produces illustrates the issue:

import numpy as np

from matplotlib import pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable

fig, ax = plt.subplots()

imax = ax.imshow(np.random.random((200, 200)), extent=[0, 100, 0, 1], aspect=100)

divider = make_axes_locatable(ax)

cax = divider.append_axes("right", size="5%", pad="2%")

cb = fig.colorbar(imax, cax=cax)

image

As a workaround, I can produce the plot I'm looking for using ImageGrid:

import numpy as np

from matplotlib import pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid

fig = plt.figure(1, (8, 4))

grid = ImageGrid(fig, 111, nrows_ncols = (1, 1), axes_pad=0.1, cbar_mode='single')

imax = grid[0].imshow(np.random.random((200, 200)), extent=[0, 100, 0, 1], aspect=100)

cax = grid.cbar_axes[0]

cb = fig.colorbar(imax, cax=cax)

image

I think this might be related to #3286. Not sure if it's an out and out duplicate or just another symptom of the same basic issue with make_axes_locatable.

Some version info:

numpy 1.9.2
matplotlib 1.4.3
python 2.7.9

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions