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

Matplotlib and Cairo layouts do not look the same #482

Open
vtraag opened this issue Dec 14, 2021 · 8 comments
Open

Matplotlib and Cairo layouts do not look the same #482

vtraag opened this issue Dec 14, 2021 · 8 comments
Labels
todo Triaged for implementation in some unspecified future version

Comments

@vtraag
Copy link
Member

vtraag commented Dec 14, 2021

Describe the bug
The layout coordination systems in matplotlib and cairo are using inverted y-axis from each other.

To reproduce

g = ig.Graph.Famous('Zachary')
ig.plot(g)

yields

image

while

fig, ax = plt.subplots()
ig.plot(g, target=ax)

yields
image

It would be nice if the two coordination systems would align. Of course, I understand that both systems have their own drawing systems and Cairo probably uses a top-left coordinate system (i.e. positive y-axis goes down in the picture) while matplotlib uses a figure coordinate system (i.e. positive y-axis goes up in the picture). To me, it seems most natural to stick to a matplotlib type coordinate system. Could we perhaps simply always invert the y coordinate before drawing in Cairo?

Version information
Development version from develop branch.

@iosonofabio
Copy link
Member

ax.invert_yaxis() before or after the plot inverts the y axis in mpl... would you like me to invert it by default?

@ntamas
Copy link
Member

ntamas commented Dec 14, 2021

I think we should stick to the defaults with Matplotlib and invert the Cairo plot instead. I'd vote for that because it is not nice if igraph messes around with the axis direction of the ax object that the user passes to the plot function (unless we are careful and revert it when we are done, even if we exit with an exception).

@vtraag
Copy link
Member Author

vtraag commented Dec 15, 2021

Cairo is also the lower level drawing interface, so there it makes sense that you setup your own coordinate system for drawing. Perhaps it even has direct support for custom coordinate systems?

@iosonofabio
Copy link
Member

iosonofabio commented Dec 15, 2021 via email

@ntamas
Copy link
Member

ntamas commented Dec 15, 2021

Cairo has support for arbitrary transformation matrices so you can "push" a transformation to a Cairo context; this allows you to flip the axes, or scale them, or rotate/skew the whole thing. However, if we flip the Y axis permanently, we break the code for people who have drawn additional stuff on a Cairo context manually, plus we may potentially break the code that aligns labels above/below the vertices. I'd probably mess around with the call to layout.fit_into(...) in the graph drawing code; this is the part that takes the layout and scales the coordinates in a way that they fit into the bounding box that the user wants to draw into. Here we could flip the Y axis in the layout before mapping it to Cairo-space.

@iosonofabio
Copy link
Member

invert_y=None -> Cairo only?

@ntamas
Copy link
Member

ntamas commented Dec 15, 2021

Something like that, yes.

@stale
Copy link

stale bot commented Feb 24, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 24, 2022
@vtraag vtraag added the todo Triaged for implementation in some unspecified future version label Feb 25, 2022
@stale stale bot removed the stale label Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
todo Triaged for implementation in some unspecified future version
Projects
None yet
Development

No branches or pull requests

3 participants