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

Drawing looks weird now... #654

Closed
nwlandry opened this issue Jan 31, 2025 · 11 comments · Fixed by #658
Closed

Drawing looks weird now... #654

nwlandry opened this issue Jan 31, 2025 · 11 comments · Fixed by #658

Comments

@nwlandry
Copy link
Collaborator

This is using the standard xgi.draw and this is an example of what I get out:

Image
@nwlandry
Copy link
Collaborator Author

I believe that PR #575 created this issue. @maximelucas any ideas?

@maximelucas
Copy link
Collaborator

maximelucas commented Feb 1, 2025

Hmm yea I added the edgecolor parameter back, and I think it's got to do with its default value.
Can you give the code for your example?
I guess you only have 2-hyperedges and you don't expect to see those dyads?

@nwlandry
Copy link
Collaborator Author

nwlandry commented Feb 3, 2025

@maximelucas if I run this code, I still get those weird lines:

import xgi
plt.figure(figsize=(1, 1))
H = xgi.Hypergraph([[1, 2, 3]])
xgi.draw(
    H,
    node_size=5,
    hull=True,
    radius=0.15,
    )

plt.savefig("test.png", dpi=1000)

(Fig size is (1, 1) so you can see the lines better)

If I set edge_ec=None, they don't go away. (Also, shouldn't they be bordering the edge anyway instead of offset from the border?)

@maximelucas
Copy link
Collaborator

Thanks. Ok I know what is happening. By default, edge_ec=None, in which case we set a hyperedge's edgecolor to be the same as its facecolor. But its facecolor has a default transparency alpha=0.4, so then the edge is visible and a bit darker, like in your example.

Possible solution: we add an edge_lw=0 parameter with default 0, this way there won't be any visible edge by default. Small downside: it makes getting the "hull outline" style a little longer, because now we need to specify a positive lw, like xgi.draw(H, pos=pos, hull=True, edge_fc="white", edge_lw=1).

What do you think?

@nwlandry
Copy link
Collaborator Author

nwlandry commented Feb 3, 2025

That could work! But that still doesn't fix the issue where the line is not at the border of the edge (see picture in my first post). Any idea how to fix that?

@maximelucas
Copy link
Collaborator

maximelucas commented Feb 3, 2025

Aah I didn't get that was the problem.

Okay, so it seems to be due to the transparency:

With alpha=1:

Image

But with the default alpha=0.4:

Image

So the "edge" we see is actually where the actual edge and the face overlap. It's the same with hull=True.

I'm not sure what solution we could find for that, other than maybe finding a way to not apply transparency to the edge's edge? But that doesn't sound ideal.

In most cases, I'd say setting edge_lw=0 to avoid that border would be the way to go, unless you only plot the border like in the hull outline, in which it's not a problem anymore.

@nwlandry
Copy link
Collaborator Author

nwlandry commented Feb 3, 2025

I tested it out, and I'm pretty sure that setting edge_lw=0 doesn't work...

@nwlandry
Copy link
Collaborator Author

nwlandry commented Feb 3, 2025

Thanks for the insight on this. TBH, I am not sure why we would want to have the default be transparent. I suppose that if there is no facecolor, then we won't see these weird overlapping patterns.

@maximelucas
Copy link
Collaborator

I tested it out, and I'm pretty sure that setting edge_lw=0 doesn't work...

That's because that parameter doesn't exist yet :)

TBH, I am not sure why we would want to have the default be transparent.

The transparency is for the full patch (=hyperedge), we have always had it by default because in many cases many hyperedges visually overlap. If you think it could look good without transparency we could test a few cases and see.

I suppose that if there is no facecolor, then we won't see these weird overlapping patterns.

Exactly.

To summarise, by adding the edge_lw=0 parameter, the behaviour would be as follows:

  • default: hyperedges are filled with facecolor, but there is no hyperdge edge, so the initial problem is solved
  • to draw only the hypedge edge (outline), we used to do xgi.draw(H, pos=pos, hull=True, edge_fc="white") but now we would need to do xgi.draw(H, pos=pos, hull=True, edge_fc="white", edge_lw=1) to ge the same result.

@nwlandry
Copy link
Collaborator Author

nwlandry commented Feb 3, 2025

Gotcha. That sounds great! Is there any way to control the alpha of the border vs. alpha of the edge?

@maximelucas
Copy link
Collaborator

Gotcha. That sounds great! Is there any way to control the alpha of the border vs. alpha of the edge?

I don't think matplotlib allows that in any simple way. The call to plot the hyperedges uses PatchCollection:

edge_collection = PatchCollection(
        patches,
        facecolors=edge_fc_colors,
        array=edge_fc_arr,  # will be mapped by PatchCollection
        cmap=edge_fc_cmap,
        edgecolors=edge_ec,
        alpha=alpha,
        zorder=max_order - 2,  # below dyads
        linewidth=edge_lw,
    )

which has a single alpha parameter. I tried forcing the alpha value of the edgecolor with edge_ec=(1, 0, 0, 1) but it doesn't work.
Do you want to be able to see the border and have a filled hyperedge in general, or just for a specific use case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants