#7570 closed defect (fixed)
Make plot methods accept 'empty' input to return empty Graphics object
Reported by: | chapoton | Owned by: | was |
---|---|---|---|
Priority: | minor | Milestone: | sage-4.6.2 |
Component: | graphics | Keywords: | list_plot, beginner |
Cc: | jason, ryan | Merged in: | sage-4.6.2.rc0 |
Authors: | Ryan Grout | Reviewers: | Aly Deines, Gagan Sekhon |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
list_plot does not accept empty lists:
list_plot([1],rgbcolor=(1,0,0))+list_plot([],rgbcolor=(0,0,1)) IndexError: list index out of range
does not work, whereas
list_plot([1],rgbcolor=(1,0,0))+list_plot([2],rgbcolor=(0,0,1))
does work. It would be nicer if list_plot of empty lists gives an empty graphics object.
Attachments (4)
Change History (32)
comment:1 Changed 11 years ago by
- Summary changed from default : list_plot of empty lists to Make plot methods accept 'empty' input to return empty Graphics object
comment:2 Changed 11 years ago by
- Cc jason added
comment:3 Changed 11 years ago by
- Keywords beginner added
Changed 10 years ago by
make list_plot() and point() accept empty lists and return empty Graphics() object
comment:4 Changed 10 years ago by
- Status changed from new to needs_work
comment:5 Changed 10 years ago by
- Cc ryan added
comment:6 Changed 10 years ago by
- Status changed from needs_work to needs_review
The patch was made against sage-4.6.0
It handles empty lists as input to arrow, line, point, and plot.
I'm not sure what other plotting functions would benefit from empty lists as input.
comment:7 Changed 10 years ago by
- Status changed from needs_review to needs_work
sage/plot/point.py fails.
When I passed an empty list I got an error.
sage: point([]) ERROR: An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line statement', (273, 0))
ValueError? Traceback (most recent call last)
/Applications/sage4.6/devel/sage-main/<ipython console> in <module>()
/Applications/sage4.6/local/lib/python2.6/site-packages/IPython/Prompts.pyc in call(self, arg)
549 550 # and now call a possibly user-defined print mechanism
--> 551 manipulated_val = self.display(arg)
552 553 # user display hooks can change the variable to be stored in
/Applications/sage4.6/local/lib/python2.6/site-packages/IPython/Prompts.pyc in _display(self, arg)
575 return IPython.generics.result_display(arg) 576 except TryNext?:
--> 577 return self.shell.hooks.result_display(arg)
578 579 # Assign the default display method:
/Applications/sage4.6/local/lib/python2.6/site-packages/IPython/hooks.pyc in call(self, *args, kw)
139 #print "prio",prio,"cmd",cmd #dbg 140 try:
--> 141 ret = cmd(*args, kw)
142 return ret 143 except ipapi.TryNext?, exc:
/Applications/sage4.6/local/lib/python2.6/site-packages/sage/misc/displayhook.pyc in result_display(ip_self, obj)
148 # IPython's default result_display() uses the IPython.genutils.Term.cout stream. 149 # See also local/lib/python2.6/site-packages/IPython/hooks.py.
--> 150 print_obj(IPython.genutils.Term.cout, obj)
151 152 def displayhook(obj):
/Applications/sage4.6/local/lib/python2.6/site-packages/sage/misc/displayhook.pyc in print_obj(out_stream, obj)
140 if _check_tall_list_and_print(out_stream, obj): 141 return
--> 142 print >>out_stream, obj
143 144 def result_display(ip_self, obj):
/Applications/sage4.6/local/lib/python2.6/site-packages/sage/structure/sage_object.so in sage.structure.sage_object.SageObject?.repr (sage/structure/sage_object.c:1341)()
/Applications/sage4.6/local/lib/python2.6/site-packages/sage/plot/plot.pyc in _repr_(self)
1078 """ 1079 if SHOW_DEFAULT:
-> 1080 self.show()
1081 return 1082 else:
/Applications/sage4.6/local/lib/python2.6/site-packages/sage/plot/misc.pyc in wrapper(*args, kwds)
82 kwds[self.name + "options"] = suboptions 83
---> 84 return func(*args, kwds)
85 86 from sage.misc.sageinspect import sage_getsource
/Applications/sage4.6/local/lib/python2.6/site-packages/sage/plot/plot.pyc in show(self, kwds)
1737 if optionsfilename? is None: 1738 optionsfilename? = sage.misc.misc.tmp_filename() + '.png'
-> 1739 self.save(options)
1740 os.system('%s %s 2>/dev/null 1>/dev/null &' % \ 1741 (sage.misc.viewer.browser(), optionsfilename?))
/Applications/sage4.6/local/lib/python2.6/site-packages/sage/plot/plot.pyc in save(self, filename, dpi, savenow, *args, kwds)
2386 options=dict() 2387 optionstransparent?=kwds.pop('transparent',False)
-> 2388 figure=self.matplotlib(*args, kwds)
2389 # You can output in PNG, PS, EPS, PDF, or SVG format, depending on the file extension. 2390 # matplotlib looks at the file extension to see what the renderer should be.
/Applications/sage4.6/local/lib/python2.6/site-packages/sage/plot/plot.pyc in matplotlib(self, filename, xmin, xmax, ymin, ymax, figsize, figure, sub, axes, axes_labels, fontsize, frame, verify, aspect_ratio, gridlines, gridlinesstyle, vgridlinesstyle, hgridlinesstyle, show_legend, legend_options, axes_pad, ticks_integer, tick_formatter, ticks)
1954 #add all the primitives to the subplot 1955 for g in self.objects:
-> 1956 g._render_on_subplot(subplot)
1957 1958 #add the legend if requested
/Applications/sage4.6/local/lib/python2.6/site-packages/sage/plot/point.pyc in _render_on_subplot(self, subplot)
271 scatteroptions={} 272 if not faceted: scatteroptionsedgecolors? = 'none'
--> 273 subplot.scatter(self.xdata, self.ydata, s=s, c=c, alpha=a, zorder=z, label=optionslegend_label?, scatteroptions)
274 275
/Applications/sage4.6/local/lib/python2.6/site-packages/matplotlib/axes.pyc in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, faceted, verts, kwargs)
5811 temp_y = y 5812
-> 5813 minx = np.amin(temp_x)
5814 maxx = np.amax(temp_x) 5815 miny = np.amin(temp_y)
/Applications/sage4.6/local/lib/python2.6/site-packages/numpy/core/fromnumeric.pyc in amin(a, axis, out)
1641 except AttributeError?: 1642 return _wrapit(a, 'min', axis, out)
-> 1643 return amin(axis, out)
1644 1645
ValueError?: zero-size array to ufunc.reduce without identity
comment:8 Changed 10 years ago by
Thanks for working on polishing these things!
One quick comment from just glancing at the patch: there is a typo that occurs twice in the patch: "returns and empty plot" (where "and" should be "an").
comment:9 Changed 10 years ago by
funny...I can't reproduce this error on my local sage install. However, on a remote sage install (i.e., sage.math), I get the error. However, the error is triggered (I think) because the remote installation can't display graphics.
Try: [[[ a = point([]) type(a) ]]] a is of type sage.plot.plot.Graphics()
comment:10 Changed 10 years ago by
Try: a = point([]) type(a)
a is of type sage.plot.plot.Graphics
comment:11 Changed 10 years ago by
- Status changed from needs_work to needs_review
- fixed the typos
- changed arrow2d a bit.
comment:12 Changed 10 years ago by
This latest patch now fixes the bug _actually_ described in the ticket :)
comment:13 Changed 10 years ago by
- Reviewers set to Aly Deines
The only test that didn't pass was ./sage -t devel/sage/sage/plot/arrow.py and I think it's only because you have line 412 in:
sage: arrow2d(headpoint=None, tailpoint)
If you delete that line, the tests pass and everything looks good.
comment:14 Changed 10 years ago by
- Status changed from needs_review to positive_review
comment:15 Changed 10 years ago by
Positive reviewer, can you add your (real) name to the reviewer list?
comment:16 Changed 10 years ago by
- Reviewers changed from Aly Deines to Aly Deines, Gagan Sekhon
comment:17 Changed 10 years ago by
- Milestone set to sage-4.6.2
comment:18 Changed 10 years ago by
- Status changed from positive_review to needs_info
Please specify which patches have to be applied.
comment:19 Changed 10 years ago by
- Description modified (diff)
- Status changed from needs_info to needs_review
comment:20 Changed 10 years ago by
- Status changed from needs_review to positive_review
comment:21 Changed 10 years ago by
- Status changed from positive_review to needs_work
- Work issues set to update commit message
I hate to do this, because I *really* want this in - just yesterday had to write all sorts of dumb if/then clauses to get around this. But the commit message on the most recent patch is totally uninformative, and unfortunately I don't have time to fix that now.
comment:22 Changed 10 years ago by
- Work issues changed from update commit message to commit message, sphinx
There is also a Sphinx error:
/mnt/usb1/scratch/jdemeyer/merger/sage-4.6.2.alpha3/local/lib/python2.6/site-packages/sage/plot/plot.py:docstring of sage.plot.plot:157: (ERROR/3) Unexpected indentation.
comment:23 Changed 10 years ago by
Can somebody please fix the trivial issues with this ticket?
comment:24 Changed 10 years ago by
- Description modified (diff)
- Status changed from needs_work to needs_review
I think this fixes both issues, as well as corrects several 'emtpy' occurrences.
comment:25 Changed 10 years ago by
- Status changed from needs_review to positive_review
comment:26 Changed 10 years ago by
- Work issues commit message, sphinx deleted
comment:27 Changed 10 years ago by
- Merged in set to sage-4.6.2.rc0
- Resolution set to fixed
- Status changed from positive_review to closed
comment:28 Changed 9 years ago by
There is a problem with the code on the final merged patch: why wasn't len()==0 used as a test? The problem is illustrated here: http://groups.google.com/group/sage-support/browse_thread/thread/fb53b9d908acfb4
I've opened #11787 to correct this.
Incidentally, this is also true of things like point(), where an empty list of points yields an error (as far as I remember). We should check ALL plot methods to ensure that empty input yields Graphics() or something like that, at least for the 2-d versions. Changing summary appropriately.