Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geom_imshow and scale_y_reverse #1210

Open
poke1024 opened this issue Oct 16, 2024 · 3 comments
Open

geom_imshow and scale_y_reverse #1210

poke1024 opened this issue Oct 16, 2024 · 3 comments
Labels
Milestone

Comments

@poke1024
Copy link

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

Bildschirmfoto 2024-10-16 um 10 11 44

i.e. the image gets clipped at y = 0. Things work fine when removing scale_y_reverse, however without the reversed scale.

@alshan
Copy link
Collaborator

alshan commented Oct 17, 2024

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 alshan added the * label Oct 17, 2024
@alshan alshan added this to the New milestone Oct 17, 2024
@poke1024
Copy link
Author

poke1024 commented Nov 7, 2024

@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.

@alshan
Copy link
Collaborator

alshan commented Nov 7, 2024

Oh, great! I assumed your intention was to reverse the y-axis AND flip the image accordingly.

@alshan alshan modified the milestones: New, 2025Q1 Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants