Closed jasongrout closed 10 years ago
It would be nice if the text display indicated this, instead of "[, ]". Maybe something like "[
,
]", since the objects actually are there. It misleadingly looks like you have an empty list.
I agree. However, I have absolutely no clue how or even if this is possible to implement in Python. I almost think it isn't. More precisely, we could easily make it so we have
sage: plot(sin, 0,1)
Actually, I vaguely recall there is a "displayhook" in Python that is called when one types
sage: <arbitrary object>
Maybe we could overload that so if _repr_
on each graphics object, we call str.
William
It's weird. Every time I think something is impossible I immediately seem to think of a solution...
Another idea: make it return
It's weird. Every time I think something is impossible I immediately seem to think of a solution...
We ought to put you in charge of more hard problems! So...do you think it's impossible to prove the Riemann hypothesis? :)
I think either of these solutions works okay, but I prefer the first since it clearly tells the user that they just constructed a list of graphic objects.
sage: [graphic1, graphic2]
# Displays each graphic, as well as:
[<graphic object>, <graphic object>]
sage: [graphic1, graphic2]
# Displays each graphic, but doesn't print anything
Just for comparison, Mathematica 6 actually prints out the graphics, surrounded by the delimiters (so the graphics are really inside the list and appear that way) when using the notebook and prints out just a string representation {-Graphics-} when used from the command line.
This idea of Jason Grout is the sort of thing we can do to solve this sort of problem:
def pretty_print (object):
if object is None:
return
if isinstance(object, (sage.plot.plot.Graphics, sage.plot.plot3d.base.Graphics3d)):
print repr(object)
return
import __builtin__
__builtin__._=object
try:
print html("$$"+latex(object)+"$$")
except:
import sys
sys.__displayhook__(object)
def notebook_pretty(enable=True):
import sys
if enable:
sys.displayhook = pretty_print
else:
sys.displayhook = sys.__displayhook__
# To enable the pretty-printing
notebook_pretty(True)
See #1922 for the above pretty_print functions.
Appears to be fixed, most probably as part of #14469. And there is already a doctest covering this behaviour.
Reviewer: Frédéric Chapoton
Ok, I think this can be closed.
CC: @kcrisman
Component: graphics
Reviewer: Frédéric Chapoton
Issue created by migration from https://trac.sagemath.org/ticket/1912