geom_imshow and scale_y_reverse
Combining geom_imshow with scale_y_reverse does not seem to work:
(
ggplot()
+ scale_y_reverse()
+ geom_imshow(pixels, extent=[0, im.width, im.height, 0])
)
produces
i.e. the image gets clipped at y = 0. Things work fine when removing scale_y_reverse, however without the reversed scale.
Unfortunately, geom_imshow() doesn't play well with positional scale/coord system transformations at the moment.
There is a workaround that you can try:
(
ggplot()
+ scale_y_reverse()
+ geom_imshow(pixels, extent=[0, im.width, 0, -im.height])
+ ylim(0, im.height)
)
@alshan Thank you for the workaround. This produces a full image with correct axes, but unfortunately the image is now flipped vertically, i.e. the mapping of y coordinate to pixel value is broken. Building on your suggestion, I was finally able to achieve what I wanted using:
ggplot() + geom_imshow(pixels, extent=[0, im.width, -im.height, 0]) + ylim(0, -im.height)
That puts the pixel at pixels[0, 0] to the top left, and the y axis position there is 0.
Oh, great! I assumed your intention was to reverse the y-axis AND flip the image accordingly.