-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Following a brief discussion on Gitter, I've decided to open an issue here but I'm not 100% sure if this is a bug or intended behavior. The following script compares the usage of origin and extent when the limits are fixed to the same intervals and same axis direction:
import numpy as np
import matplotlib.pyplot as plt
image = np.arange(100).reshape((10, 10))
subplot = 0
fig = plt.figure(figsize=(8, 8))
for extent in [None, [1, 9, 1, 9]]:
for origin in ['lower', 'upper']:
subplot += 1
ax = fig.add_subplot(2, 2, subplot)
ax.imshow(image, interpolation='nearest', origin=origin,
extent=extent)
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
ax.set_title('extent={0} origin={1}'.format(extent, origin),
fontsize=8)
fig.savefig('thumbs.png')
The output is:
As you can see, when no extent is specified, the origin keyword has no impact on the result whereas it does when the extent is specified.
There is either a bug here, or something that exists for historical reasons that deserves its own documentation section.
In any case, the documentation for origin
doesn't make much sense:
origin : ['upper' | 'lower'], optional, default: None
Place the [0,0] index of the array in the upper left or lower left
corner of the axes. If None, default to rc `image.origin`.
the concept of 'upper left' or 'lower left' is tricky since the axes can be made to go in either direction, so whether [0,0] is at the upper or lower corner visually depends on the direction of the axes.
It seems that when extent is not specified, origin simply means that the y limits are flipped but this can be reverted by setting ylim. When extent is present, the array is truly flipped vertically.