#9529: in graph_plot.py, sometimes get "libpng error: Image width or height is
zero in IHDR"
-----------------------+----------------------------------------------------
   Reporter:  rlm      |       Owner:  AlexGhitza
       Type:  defect   |      Status:  new       
   Priority:  major    |   Milestone:            
  Component:  algebra  |    Keywords:            
     Author:           |    Upstream:  N/A       
   Reviewer:           |      Merged:            
Work_issues:           |  
-----------------------+----------------------------------------------------

Comment(by cwitty):

 To reproduce this fairly quickly, type:
 {{{
 sage.plot.plot.DOCTEST_MODE = True
 while True:
     d = DiGraph({}, loops=True, multiedges=True, sparse=True)
     d.add_edges([(0,0,'a'),(0,0,'b'),(0,1,'c'),(0,1,'d'),
             (0,1,'e'),(0,1,'f'),(0,1,'f'),(2,1,'g'),(2,2,'h')])
     GP = d.graphplot(vertex_size=100, edge_labels=True,
 color_by_label=True, edge_style='dashed')
     GP.set_edges(edge_style='solid')
     GP.plot()
 }}}
 at a sage: prompt.

 I spent some time looking into this; here are the results I found before I
 gave up.

 We draw our plots with bbox_inches='tight', which means:
 {{{
             Bbox in inches. Only the given portion of the figure is
             saved. If 'tight', try to figure out the tight bbox of
             the figure.
 }}}

 There's also a parameter pad_inches:
 {{{
             Amount of padding around the figure when bbox_inches is
             'tight'.
 }}}

 matplotlib gets its "tight bbox" with the appropriately-named
 get_tightbbox() function, in src/lib/matplotlib/figure.py.  Its docstring
 proclaims,
 {{{
         It only accounts axes title, axis labels, and axis
         ticklabels. Needs improvement.
 }}}
 and it's true, it does need improvement.

 Our graph_plot figure has "empty" axes (no title, labels, or ticklabel),
 but it does have an axes object with a size, which gets used for the tight
 bbox.  I believe that size comes indirectly from get_minmax_data in
 sage/plot/plot.py, but I'm not sure.

 I can think of a few possibilities to fix the problem, ordered from best
 to worst.

 1) Fix matplotlib get_tightbbox() to actually be a bounding box for the
 drawing, not just for the "axes".  This would definitely be best... it
 would also fix problems like graphs with loops going off the edge of the
 plot, etc.

 2) Adjust our get_minmax_data functions to be closer to a correct bounding
 box.  For instance, currently get_minmax_data on a Text object only looks
 at the center of the text, and doesn't take the size into account.
 There's a limit to how good a job we could do, though... we don't want to
 start digging through font metrics, etc.

 3) Set pad_inches to make all our plots "a little bit bigger".  The
 downside, of course, is that this simple approach would affect *all* our
 plots.

 Like I said, I'm giving up now.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/9529#comment:3>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to