Changeset 7733:90f94138caf3


Ignore:
Timestamp:
12/12/07 10:34:36 (5 years ago)
Author:
William Stein <wstein@…>
Branch:
default
Message:

Trac #1480 -- embedded mathematica graphics in sage notebook.

Location:
sage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sage/interfaces/mathematica.py

    r7672 r7733  
    226226                    FunctionElement, AsciiArtString) 
    227227 
    228 from sage.misc.misc import verbose 
     228from sage.misc.misc import verbose, graphics_filename 
    229229 
    230230def clean_output(s): 
     
    390390        return "}" 
    391391 
     392    ########################################### 
     393    # System -- change directory, etc 
     394    ########################################### 
     395    def chdir(self, dir): 
     396        """ 
     397        Change Mathematica's current working directory. 
     398         
     399        EXAMPLES: 
     400        """ 
     401        self.eval('SetDirectory["%s"]'%dir) 
     402 
    392403    def _true_symbol(self): 
    393404        return '         True' 
     
    454465        P = self._check_valid() 
    455466        return P.get(self._name, ascii_art=True) 
     467 
     468    def show(self, filename=None, ImageSize=600): 
     469        """ 
     470        Show a mathematica plot in the Sage notebook. 
     471 
     472        EXAMPLES: 
     473            sage: P = mathematica('Plot[Sin[x],{x,-2Pi,4Pi}]') 
     474            sage: show(P) 
     475            sage: P.show(ImageSize=800)         
     476        """ 
     477        P = self._check_valid() 
     478        if filename is None: 
     479            filename = graphics_filename() 
     480        orig_dir = P.eval('Directory[]').strip() 
     481        P.chdir(os.path.abspath(".")) 
     482        s = 'Export["%s", %s, ImageSize->%s]'%(filename, self.name(), ImageSize) 
     483        P.eval(s) 
     484        P.chdir(orig_dir) 
    456485 
    457486    def str(self): 
  • sage/misc/functional.py

    r7471 r7733  
    2929import sage.server.support 
    3030import sage.interfaces.expect 
     31import sage.interfaces.mathematica 
    3132 
    3233 
     
    875876    OPTIONAL INPUT: 
    876877        filename -- (default: None) string 
     878 
     879    SOME OF THESE MAY APPLY: 
    877880        dpi -- dots per inch 
    878881        figsize -- [width, height] (same for square aspect) 
     
    886889        except AttributeError: 
    887890            pass 
     891    if isinstance(x, sage.interfaces.mathematica.MathematicaElement): 
     892        return x.show(*args, **kwds) 
     893         
    888894    _do_show(x) 
    889895 
Note: See TracChangeset for help on using the changeset viewer.