Skip to content

Embedded nodes in draw_multilayer#612

Draft
thomasrobiglio wants to merge 5 commits into
xgi-org:devfrom
thomasrobiglio:embedded-nodes-multilayer
Draft

Embedded nodes in draw_multilayer#612
thomasrobiglio wants to merge 5 commits into
xgi-org:devfrom
thomasrobiglio:embedded-nodes-multilayer

Conversation

@thomasrobiglio

Copy link
Copy Markdown
Collaborator

Adresses #436. I am still working on this to try to change as little as possible to behavior of the function.

@thomasrobiglio thomasrobiglio marked this pull request as draft October 28, 2024 15:01
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@maximelucas

Copy link
Copy Markdown
Collaborator

Quoting @thomasrobiglio :

Yes I thought the same about the nodes' shape. What can be more relevant is the following:

I am struggling to have a node collection returned when calling the function (which then allows to have the colorbars and the cool stuff we have for the standard drawing function).

This is because I need to create a separate Circle patch that is transformed into a 3D patch for each node (in each level) separately, and I have not managed to group these objects in a collection so far. I will keep looking for a solution, if you have ideas they are most welcome, I am a bit stuck--I have opened a draft pr #612

Yes, I thought that might be a problem. Matplotlib has different types of collections, including a PatchCollection with an example here. Would this work with the 3D patches?

@thomasrobiglio

Copy link
Copy Markdown
Collaborator Author

Thank you @maximelucas! this is more or less the documentation I was looking at when working on this... let's see if I can find something that works :).

@thomasrobiglio

Copy link
Copy Markdown
Collaborator Author

This could be a way out... to have the circles for the nodes drawn as polygons with many sides. It's not the best thing to do, but I could not find a way to use a collection of circle objects in 3d.

With a couple of tweaks, I should be able to make it work from outside as the function we have in the stable version now.

@maximelucas

Copy link
Copy Markdown
Collaborator

Could you show us what the viz would look like? Is it like your example in the issue you opened?

@thomasrobiglio

Copy link
Copy Markdown
Collaborator Author

Something like this---if you have more >20 points to build the polygon you cannot see that it's not an actual circle:

try

@kaiser-dan kaiser-dan added help wanted Extra attention is needed viz long term Issues that require significant work and are low priority, so are closed for now. labels Feb 26, 2026
@kaiser-dan kaiser-dan changed the base branch from main to dev February 26, 2026 15:43
@maximelucas

Copy link
Copy Markdown
Collaborator

@thomasrobiglio nice, even if we view it from above? Do you think the colors of the nodes are still visible enough (for example when we plot stats)?

@thomasrobiglio

Copy link
Copy Markdown
Collaborator Author

thanks for the ping @maximelucas! tbh this had fallen into oblivion on my to-do list... I'll try to make some further progress

@maximelucas

maximelucas commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Apparently you could do something like this instead:
Build real Circle patches (true circles, no polygon hack), put them in one PatchCollection with the colormap-array, then convert to 3D (with art3d.patch_collection_2d_to_3d), mirroring the pattern of edge_collection already uses at draw.py:843:

  # one Circle per node per layer
  patches = [Circle((x, y), radius) for ... ]
  node_collection = PatchCollection(
      patches,
      array=node_fc_arr,      # values → mapped by the collection (enables colorbar)
      cmap=node_fc_cmap,
      edgecolors=node_ec,
      linewidths=node_lw,
  )
  art3d.patch_collection_2d_to_3d(node_collection, zs=z_per_patch, zdir="z",
                                  depthshade=False)   # keep stat colors faithful
  ax.add_collection3d(node_collection)

Pros compared to current PR solution:

  1. Real circles, not 30-gons.
  2. One ScalarMappable collection → plt.colorbar(node_collection) and stat-based coloring work, like the 2D draw_nodes.
  3. You can collect circles across all layers into a single collection (pass per-patch zs), so draw_multilayer can
    return one node_collection matching the 2D API, instead of an unreturned per-layer collection.
  4. It reuses the exact idiom already in draw.py (the edge_collection block), so it's consistent.
  5. depthshade=False keeps colormap colors accurate.

Worth having a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed long term Issues that require significant work and are low priority, so are closed for now. viz

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants