Opened 11 years ago

Last modified 10 years ago

#9211 closed defect

graph vertices cut off — at Version 17

Reported by: jason Owned by: jason, mvngu, ncohen, rlm
Priority: major Milestone: sage-4.8
Component: graph theory Keywords:
Cc: rbeezer, kcrisman, kini Merged in:
Authors: Jason Grout Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by ppurka)

Though #7299 helped, graph vertices are still cut off.

With the updated matplotlib spkg at #9210, we can turn off clipping of the matplotlib scatterplot, or with a more recent (SVN right now) version of matplotlib, we could probably add some bbox_extra_artists to the savefig which takes those artists into account when calculating the bounding box (when bbox_inches='tight').

Either way, a real fix should be possible soon.


First apply trac-9211-fix_cut_vertices_in_graphs.patch and then apply trac_9211_digraph_clipping.patch to `SAGE_ROOT/devel/sage`.

Change History (23)

comment:1 Changed 11 years ago by jason

Here is a good example showing the problem (still):

a=matrix([[1,2],[3,4]])

var('x y z w')
b=matrix([[x,y],[z,w]])

a.set_immutable()
b.set_immutable()

K=DiGraph({a:[b]})
show(K, vertex_size=800)

Changed 11 years ago by jason

comment:2 Changed 11 years ago by jason

  • Status changed from new to needs_review

This patch depends on the matplotlib spkg at #9221. I don't know if the patch is very elegant. I'll trust the reviewer's comments on that. The problem is that it lets the scatter plot vertices extend beyond the frame (relying on the user adjusting the axes_pad option to extend the frame).

comment:3 Changed 11 years ago by jason

  • Authors set to Jason Grout
  • Work issues set to depends on #9221

comment:4 Changed 11 years ago by jason

  • Status changed from needs_review to needs_work

The patch doesn't work for multiple-edge graphs (they are drawn completely differently than graphs without multiple edges). In fact, we probably ought to draw all graphs using CircleCollection? objects rather than scatter_plot or Circles.

comment:5 Changed 11 years ago by jason

Here's how to draw circles like the ones in scatter plot (where the size doesn't change as you make the figure smaller or bigger: use a CircleCollection? argument and use different transforms to specify location and size coordinates. See http://sourceforge.net/mailarchive/forum.php?thread_name=AANLkTim6ZnGiOV1RTRBz0uBMF5y67xyrDp%2BkVSCBtkrB%40mail.gmail.com&forum_name=matplotlib-users

comment:6 Changed 11 years ago by jason

See also http://groups.google.com/group/networkx-discuss/browse_thread/thread/b95fda9813fae67d for code/ideas for rewriting the graph drawing.

comment:7 Changed 10 years ago by jason

I think this patch might take just a little to clean up. Most of the patch is just adding comments to explain the code or reformatting long lines. The big key is the clip=False arguments and the code to add things to the bbox_extra_artists.

I think the patch might just need some doctests and testing. The other comments I put in above can be moved to another ticket that does a bigger revamp of graph drawing.

comment:8 Changed 10 years ago by kcrisman

  • Cc kcrisman added

comment:9 Changed 10 years ago by kcrisman

  • Work issues depends on #9221 deleted

comment:10 Changed 10 years ago by kini

  • Cc kini added

Changed 10 years ago by ppurka

( Fix cut off vertices in graphs ) Apply to devel/sage/

Changed 10 years ago by ppurka

( Add additional padding to graphs ) Apply to devel/sage

Changed 10 years ago by ppurka

Output with only the earlier patch (modified for 4.7.2)

Changed 10 years ago by ppurka

Output with patch for additional padding

comment:11 Changed 10 years ago by ppurka

  • Status changed from needs_work to needs_review

Added two patches. The first one is essentially the patch by jason redone to work with 4.7.2_alpha3.

The second patch adds extra padding to all graphs. The two pngs attached are the output of

M = matrix(RDF, [[1/3, 1/3, 1/3], [0, 1/4, 3/4], [1/2, 1/4, 1/4]])
G=DiGraph(M, format='weighted_adjacency_matrix')
G.show(vertex_size=800, edge_labels=True)

The file with-additional-padding.png is the result of both the patches being applied.

Graphs currently look really bad without either of the two patches. The second patch is not a panacea for all cut off graph plots since it doesn't fix all cases. But my hope is that it fixes most commonly used cases.

comment:12 follow-up: Changed 10 years ago by jason

I'm curious why you need the extra padding patch. Are vertices still cut off using just the first patch?

comment:13 in reply to: ↑ 12 Changed 10 years ago by ppurka

Replying to jason:

I'm curious why you need the extra padding patch. Are vertices still cut off using just the first patch?

Yes. Check the plot after the first patch against the the plot after first+second patch

comment:14 Changed 10 years ago by jason

Ah, right, because the first patch only fixes undirected graphs. You are plotting a directed graph, so the changes in the patch don't apply. I'm uploading a new patch that doesn't clip digraph circles or text.

Changed 10 years ago by jason

apply after trac-9211-fix_cut_vertices_in_graphs.patch

comment:15 follow-up: Changed 10 years ago by jason

Can you try applying just trac-9211-fix_cut_vertices_in_graphs.patch and trac_9211_digraph_clipping.patch ?

comment:16 in reply to: ↑ 15 Changed 10 years ago by ppurka

Replying to jason:

Can you try applying just trac-9211-fix_cut_vertices_in_graphs.patch and trac_9211_digraph_clipping.patch ?

Excellent! Thanks. This does fix the problem for digraphs. Much better than adding random paddings.

comment:17 Changed 10 years ago by ppurka

  • Description modified (diff)
Note: See TracTickets for help on using tickets.