#16378: list_plot throws a TypeError with complex lists
--------------------------------------+------------------------
Reporter: bradlys | Owner: bradlys
Type: defect | Status: new
Priority: major | Milestone: sage-6.3
Component: packages: standard | Resolution:
Keywords: | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: | Stopgaps:
--------------------------------------+------------------------
Comment (by bradlys):
This is how list_plot works from 5.1.2. It's significantly different than
the current implementation. I'm not sure how to track down where the
changes were made as I am pretty new to fixing bugs for Sage.
{{{
from sage.plot.all import line, point
if data == {} or data == () or data == []:
return Graphics()
if isinstance(data, dict):
if plotjoined:
list_data = sorted(list(data.iteritems()))
else:
list_data = list(data.iteritems())
return list_plot(list_data, plotjoined=plotjoined, **kwargs)
if not isinstance(data[0], (list, tuple)):
data = zip(range(len(data)), data)
if isinstance(plotjoined, (list, tuple)):
raise TypeError, "The second argument 'plotjoined' should be
boolean (True or False). If you meant to plot two lists 'x' and 'y'
against each other, use 'list_plot(zip(x,y))'."
try:
if plotjoined:
return line(data, **kwargs)
else:
return point(data, **kwargs)
except (TypeError, IndexError):
# Assume we have complex-valued input and plot real and imaginary
parts.
# Need to catch IndexError because if data is, say, [(0, 1), (1,
I)],
# point3d() throws an IndexError on the (0,1) before it ever
# gets to (1, I).
from sage.rings.complex_field import ComplexField
CC = ComplexField()
# if we get here, we already did "zip(range(len(data)), data)",
# so look at z[1] in inner list
data = [(z.real(), z.imag()) for z in [CC(z[1]) for z in data]]
if plotjoined:
return line(data, **kwargs)
else:
return point(data, **kwargs)
}}}
--
Ticket URL: <http://trac.sagemath.org/ticket/16378#comment:7>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.