Opened 15 years ago

Closed 15 years ago

#1575 closed defect (fixed)

[with patch, with positive review] plotting -- fix vector plotting

Reported by: William Stein Owned by: Jason Grout
Priority: major Milestone: sage-2.10.1
Component: graphics Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges


On Dec 19, 2007 12:24 PM, Jason Grout <> wrote:
> I'm teaching linear algebra next semester and plan to use Sage.  In
> trying the "obvious" way to plot a vector:
> sage: v=vector([1,2])
> sage: v.plot().show()
> I get what looks like a step function of the coordinates. 

Yes, that's what it is.  This is very useful, e.g., when using
vectors of data, computing Fourier transforms of them, etc. 
And it works in arbitrary dimensions.  

>  Instead, I
> have to do:
> sage: v=vector([1,2])
> sage: arrow((0,0),v).show()
> which doesn't seem quite so natural to an undergraduate linear algebra
> student.  First, is there an easier way to plot a vector (yes, I know I
> don't have to define v above and could just give the coordinates to
> arrow, but usually I'll be doing something with v as a vector)?  Is it
> reasonable to redefine v.plot() to return the arrow for a vector with 3
> or fewer dimensions, or is there some bigger reason to have things the
> way they are now?

I think that would be bad, because it's potentially confusing and
unsystematic.  However, the following -- which you will like --
would be acceptable to me:

   Redefine v.plot() so for dimensions <= 3 it does what you describe above,
i.e., draws an arrow, but for dimensions >= 4 it gives an error message.
Then add an option to plot called "step", which if set to True restores
the current behavior.    

In fact, this was my intention all along, and somehow I screwed up. 
The current plot signature for vectors is:

    def plot(self, xmin=0, xmax=1, eps=None, res=None,
             connect=True, step=False, **kwds):

Notice that step=False is already there!  

-- William

Attachments (2)

vector-plot.patch (4.5 KB) - added by Jason Grout 15 years ago.
vector-plot-updated.patch (4.4 KB) - added by Jason Grout 15 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 15 years ago by William Stein

Owner: changed from William Stein to jason grout

comment:2 Changed 15 years ago by Jason Grout

Owner: changed from jason grout to Jason Grout
Status: newassigned

Changed 15 years ago by Jason Grout

Attachment: vector-plot.patch added

comment:3 Changed 15 years ago by Jason Grout

Milestone: sage-2.9.2sage-2.9.1

In vector-plot.patch, plot is redefined to behave thusly:

  • the option "type" has values 'arrow', 'point', and 'step'
  • if 1 <= dimension <= 3, default type='arrow'
  • if dimension > 3, default type='step'

The old plot function was renamed plot_step.

comment:4 Changed 15 years ago by Jason Grout

Summary: plotting -- fix vector plotting[with patch] plotting -- fix vector plotting

comment:5 Changed 15 years ago by Jason Grout

I just discovered that Arrow has been changed to arrow3d in sage 2.9.3. The patch should be updated accordingly.

Changed 15 years ago by Jason Grout

Attachment: vector-plot-updated.patch added

comment:6 Changed 15 years ago by Jason Grout

I've renamed the "type" option to "plot_type" and fixed the Arrow issue (the graphics interface changed around 2.9.3) and the doctest "eps" issue.

The vector-plot-updated.patch should be applied instead of vector-plot.patch.

comment:7 Changed 15 years ago by Carl Witty

Summary: [with patch] plotting -- fix vector plotting[with patch, with positive review] plotting -- fix vector plotting

Looks good; doctests pass.

comment:8 Changed 15 years ago by Michael Abshoff

Resolution: fixed
Status: assignedclosed

vector-plot-updated.patch merged in Sage 2.10.1.rc1.

Note: See TracTickets for help on using tickets.