GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Setting the coordinate reference system · Issue #268 · fastplotlib/fastplotlib

Setting the coordinate reference system #268

New issue
Copy link
New issue
Copy link
Closed
#313
Closed
Setting the coordinate reference system#268
#313
Copy link
Assignees
clewis7

Description

@EricThomson
EricThomson
opened on Jun 30, 2023
Issue body actions

When plotting images with add_image() it doesn't show up in the conventional orientation, but upside down (same when using ImageWidget().

face = np.array([
   [0.6, .5, .5,  0.6, 0.5, 0.5, 0.6,], # row 0
   [0.6, 0.4, .5, 0.6, 0.4, 0.5, 0.6,], # row 0.6
   [0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6,], # row 2
   [0.6, 0.6, 0.6, 0.4, 0.6, 0.6, 0.6,], # row 3
   [0.6, 0.4, 0.6, 0.6, 0.6, 0.4, 0.6,], # row 4
   [0.6, 0.6, 0.4, 0.4, 0.4, 0.6, 0.6,], # row 5
   [0.5, 0.6, 0.6, 0.6, 0.6, 0.6, 0.5,], # row 6
]);

Matplotlib plt.imshow(face, cmap='gray') output:

mpl_imshow

Fastplotlib:

import fastplotlib as fpl
plot = fpl.Plot()
plot.add_image(data=face, cmap='gray')
plot.show()
add_image

Obviously there are conventions at play here with yaxis being switched being the norm for images.

Activity

  1. kushalkolar
    changed the title [-]Image reflected on horizontal axis[/-] [+]Setting the coordinate reference system[/+] on Jul 12, 2023
  2. kushalkolar commented on Jul 12, 2023

    @kushalkolar
    kushalkolar
    on Jul 12, 2023
    Member
    More actions

    This is part of a larger discussion and we will need to wait until it stabilizes in pygfx and pylinalg before we expose it somehow in fastplotlib. See pygfx/pygfx#460

    pygfx and pylinalg just made recent changes that break things, pygfx/pygfx#556, pygfx/pygfx#563

    for now (i.e. for scipy demo) going to stick to release version of pygfx and pin to pylinalg == 0.4.0

  3. ArjunPutcha commented on Jul 17, 2023

    @ArjunPutcha
    ArjunPutcha
    on Jul 17, 2023
    Collaborator
    More actions

    for plotting 1D/timeseries biosensor data, origin in the bottom left is useful since it helps us determine if our photodiode is 'flipped'. It's hard to tell just by plotting the data whether the canvas is flipped, or if our photodiode is connected incorrectly. Perhaps having defaults where if there's an image in the grid, origin can be set top left. If line, origin set to bottom left.

    Is there a way to flip the orientation for specific subplots @kushalkolar?

  4. clewis7 commented on Jul 17, 2023

    @clewis7
    clewis7
    on Jul 17, 2023
    Member
    More actions

    @ArjunPutcha if you are using the toolbar with a gridplot then the only subplot you will flip is the currently clicked on subplot...so in order to flip a certain gridplot, you can select that subplot in the subplot dropdown or click on it and that subplot will be automatically selected!

    you can of course also manually flip the camera y-scale indexing into a given subplot

  5. ArjunPutcha commented on Jul 17, 2023

    @ArjunPutcha
    ArjunPutcha
    on Jul 17, 2023
    Collaborator
    More actions

    Wonderful! Right now it flips the x axis, not the y axis. I'll test if it's because of something I wrote wrong.

  6. kushalkolar commented on Jul 17, 2023

    @kushalkolar
    kushalkolar
    on Jul 17, 2023
    Member
    More actions

    Wonderful! Right now it flips the x axis, not the y axis. I'll test if it's because of something I wrote wrong.

    current pygfx/pylinalg bug, will fix soon.

  7. clewis7 commented on Aug 21, 2023

    @clewis7
    clewis7
    on Aug 21, 2023
    Member
    More actions

    I think after we bump to pylinalg=0.4.1 we can simply change the flip button to
    self.camera.local.y_scale = -1 as opposed to self.camera.world.y_scale = -1

    Also, I think in the future to address setting the reference as an abstraction for users in fpl what about having a kwarg for origin like so:

    import fastplotlib as fpl
    import numpy as np
    
    face = np.array([
       [0.6, .5, .5,  0.6, 0.5, 0.5, 0.6,], # row 0
       [0.6, 0.4, .5, 0.6, 0.4, 0.5, 0.6,], # row 0.6
       [0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6,], # row 2
       [0.6, 0.6, 0.6, 0.4, 0.6, 0.6, 0.6,], # row 3
       [0.6, 0.4, 0.6, 0.6, 0.6, 0.4, 0.6,], # row 4
       [0.6, 0.6, 0.4, 0.4, 0.4, 0.6, 0.6,], # row 5
       [0.5, 0.6, 0.6, 0.6, 0.6, 0.6, 0.5,], # row 6
    ])
    
    plot = fpl.Plot(origin='bottom-left')
    
    plot.add_image(data=face)
    
    plot.show()
    

    By default, the origin could be origin='top-left' as it is now and then any other option will make direct changes to the
    camera reference_up attr.

    In the example above, the plot.camera.local.reference_up would be np.array([ 0., -1., 0.])

    @kushalkolar thoughts?

  8. kushalkolar commented on Sep 20, 2023

    @kushalkolar
    kushalkolar
    on Sep 20, 2023
    Member
    More actions

    I think after we bump to pylinalg=0.4.1 we can simply change the flip button to self.camera.local.y_scale = -1 as opposed to self.camera.world.y_scale = -1

    After playing with the camera scaling local etc. we figured out that this is all that needs to be done.

    For the flip button, we can just make the flip button arrow indicate the direction of the y axis :D

  9. kushalkolar commented on Sep 20, 2023

    @kushalkolar
    kushalkolar
    on Sep 20, 2023
    Member
    More actions

    So for image plotting, we have decided:

    • when Plot.show() is called, if an ImageGraphic exists in the scene, then the y-axis is automatically flipped.

    Question: Do we want to do this for heatmap too? I think yes. In which case we can still check for ImageGraphic instances since HeatmapGraphic is just a subclass of ImageGraphic.

    This can be done after #300

  10. clewis7
    self-assigned this
    on Sep 21, 2023
  11. kushalkolar
    closed this as completedin #313on Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @clewis7
    clewis7

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402520 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.