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

in graph_plot.py, sometimes get "libpng error: Image width or height is zero in IHDR" #9529

Closed
rlmill mannequin opened this issue Jul 17, 2010 · 10 comments
Closed

in graph_plot.py, sometimes get "libpng error: Image width or height is zero in IHDR" #9529

rlmill mannequin opened this issue Jul 17, 2010 · 10 comments

Comments

@rlmill
Copy link
Mannequin

rlmill mannequin commented Jul 17, 2010

To reproduce this, you can do something like the following in bash:


sage-4.5.rc1/devel/sage-main$ for i in `seq 1 20`;
> do
>     ../../sage -t sage/graphs/graph_plot.py
> done

CC: @fchapoton @tscrim

Component: graph theory

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/9529

@rlmill rlmill mannequin added c: algebra labels Jul 17, 2010
@rlmill rlmill mannequin assigned aghitza Jul 17, 2010
@rlmill
Copy link
Mannequin Author

rlmill mannequin commented Jul 17, 2010

comment:1

See also #5906.

@rlmill
Copy link
Mannequin Author

rlmill mannequin commented Jul 17, 2010

comment:2
**********************************************************************
File "/scratch/rlmill/sage-4.5.rc1/devel/sage-main/sage/graphs/graph_plot.py", line 267:
    sage: GP.plot()
Exception raised:
    Traceback (most recent call last):
      File "/scratch/rlmill/sage-4.5.rc1/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/scratch/rlmill/sage-4.5.rc1/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/scratch/rlmill/sage-4.5.rc1/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_4[13]>", line 1, in <module>
        GP.plot()###line 267:
    sage: GP.plot()
      File "/scratch/rlmill/sage-4.5.rc1/local/lib/python/site-packages/sage/misc/displayhook.py", line 174, in displayhook   
        print_obj(sys.stdout, obj)
      File "/scratch/rlmill/sage-4.5.rc1/local/lib/python/site-packages/sage/misc/displayhook.py", line 142, in print_obj
        print >>out_stream, `obj`
      File "sage_object.pyx", line 101, in sage.structure.sage_object.SageObject.__repr__ (sage/structure/sage_object.c:1370) 
      File "/scratch/rlmill/sage-4.5.rc1/local/lib/python/site-packages/sage/plot/plot.py", line 915, in _repr_
        self.show()
      File "/scratch/rlmill/sage-4.5.rc1/local/lib/python/site-packages/sage/plot/plot.py", line 1437, in show
        self.save(DOCTEST_MODE_FILE, **options)
      File "/scratch/rlmill/sage-4.5.rc1/local/lib/python/site-packages/sage/plot/plot.py", line 1973, in save
        figure.savefig(filename,dpi=dpi,bbox_inches='tight',**options)
      File "/scratch/rlmill/sage-4.5.rc1/local/lib/python/site-packages/matplotlib/figure.py", line 1032, in savefig
        self.canvas.print_figure(*args, **kwargs)
      File "/scratch/rlmill/sage-4.5.rc1/local/lib/python/site-packages/matplotlib/backend_bases.py", line 1455, in print_figure
        **kwargs)
      File "/scratch/rlmill/sage-4.5.rc1/local/lib/python/site-packages/matplotlib/backends/backend_agg.py", line 366, in print_png
        filename_or_obj, self.figure.dpi)
    RuntimeError: Error building image
**********************************************************************

@sagetrac-cwitty
Copy link
Mannequin

sagetrac-cwitty mannequin commented Jul 17, 2010

comment:3

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.

@jasongrout
Copy link
Member

comment:4

See #9211, where similar issues are dealt with. With the new matplotlib at #9221, we can add some extra artists whose bounding boxes should be included in the tight bbox calculations (so, for example, we should be able to add the text boxes and then the tight bbox calculations would include those bounds as well).

@rlmill rlmill mannequin added c: graph theory and removed c: algebra labels Jul 19, 2010
@rlmill rlmill mannequin assigned jasongrout, nathanncohen and rlmill and unassigned aghitza Jul 19, 2010
@jm58660
Copy link
Mannequin

jm58660 mannequin commented Jul 16, 2016

comment:6

I can not reproduce this, and this is six years old. I suppose this one can be closed as the code has been changed many times. Frédéric, do you agree?

@jm58660 jm58660 mannequin added the s: needs review label Jul 16, 2016
@jm58660
Copy link
Mannequin

jm58660 mannequin commented Aug 9, 2016

comment:7

Travis, do you agree that we can close this?

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Aug 17, 2016

comment:8

Just pinging this wontfix-confirmation.

@tscrim
Copy link
Collaborator

tscrim commented Aug 17, 2016

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Aug 17, 2016

comment:9

I can't reproduce it either.

@embray
Copy link
Contributor

embray commented Aug 30, 2016

comment:10

Determined to be invalid/duplicate/wontfix (closing as "wontfix" as a catch-all resolution).

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

No branches or pull requests

4 participants