Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Location of subplot.set_aspect(...) matters for imshow #2540

Closed
@ppurka

Description

@ppurka

The location of the command subplot.set_aspect('auto') - whether it is before or after the command subplot.imshow(...) - determines whether the aspect ratio is properly set. The aspect ratio is properly set only if the set_aspect command follows the imshow command. The same holds true if other values are passed to set_aspect, such as set_aspect(0.05).

This discrepancy is most pronounced for plots with very disproportionate vertical and horizontal ranges. An example code is given below:

x = range(10)
y = [10**_ for _ in range(10)]
xmuly = [[i*j for j in y] for i in x]
# Uncomment this and comment the set_aspect below imshow to see the bug.
#subplot.set_aspect('auto', adjustable='box')
subplot.imshow(xmuly, origin='lower', cmap='jet', extent=[0,9,10**0,10**9], interpolation='catrom')
subplot.set_aspect('auto', adjustable='box')

This code can be tested live here.

This problem is not present when subplot.plot(...) is used. The aspect ratio is always correctly set irrespective of whether the set_aspect command comes before or after the plot command.

Corresponding Sage ticket: http://trac.sagemath.org/15315

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