Line Plots

6 views
Skip to first unread message

Eric Jackson

unread,
Sep 14, 2009, 12:05:26 AM9/14/09
to sage-support
Does sage have the capability of allowing the user to view x and y
coordinates (x,y) by moving his/her cursor along the line created in a
plot? Matlab and Microsoft Excel have a feature, that allow the user
to view xy values as he/she moves their cursor along the line of a
plot. In other words, the xy coordinates literally appear as the
cursor is moved along the plot. Any help with this would be greatly
appreciated. Thanks!

William Stein

unread,
Sep 14, 2009, 6:20:12 AM9/14/09
to sage-s...@googlegroups.com

Unfortunately, Sage doesn't *yet* have this capability. It will in
the near future.

William

kcrisman

unread,
Sep 14, 2009, 8:57:53 AM9/14/09
to sage-support


On Sep 14, 6:20 am, William Stein <wst...@gmail.com> wrote:
Are you referring to the possibility of viewer='flot'?

- kcrisman

Jason Grout

unread,
Sep 14, 2009, 12:10:05 PM9/14/09
to sage-s...@googlegroups.com
William Stein wrote:


> It will in the near future.

Are you thinking of the matplotlib html5 canvas backend that is being
developed? Or is there something else that you are doing?

Jason

William Stein

unread,
Sep 14, 2009, 12:17:57 PM9/14/09
to sage-s...@googlegroups.com

I'm going to do *something*. I think there are numerous ways to solve
this problem if one tries hard. First I would do something with
javascript and png's for complete compatibility with our existing
infrastructure, but of course that's just one thing.

William

Jason Grout

unread,
Sep 14, 2009, 12:31:10 PM9/14/09
to sage-s...@googlegroups.com


Well, then just for reference, here is a recent matplotlib thread from
someone working on an html5 canvas backend to matplotlib:

http://sourceforge.net/mailarchive/forum.php?thread_name=6e8d907b0909012053s19e7c5fl29cdcd0e1fab1d50%40mail.gmail.com&forum_name=matplotlib-devel

They might be interested in collaborating, or motivated if they saw
their work being used immediately.

Of course, this doesn't address moderately old or dysfunctional browsers
that don't have html5 canvas.

Jason

Eric Jackson

unread,
Sep 14, 2009, 4:26:22 PM9/14/09
to sage-support
I'm not thinking of matplotlib html5. However, I am fairly new to
working with Sage. I will do some research to see what matplotlib
html5 is about.

As far as what I'm doing, I've created a plot of a function, say sin
(t) that is evaluated from t, -2*pi,2*pi. As I am viewing the plot,
I would like to move my cursor along the sin(t) curve and in real time
see what the xy coordinates are at various locations on the curve.

Eric

Jason Grout

unread,
Sep 14, 2009, 4:37:54 PM9/14/09
to sage-s...@googlegroups.com
Eric Jackson wrote:
> I'm not thinking of matplotlib html5. However, I am fairly new to
> working with Sage. I will do some research to see what matplotlib
> html5 is about.

It's not finished. Here is a demo of what gnuplot can do with an html5
canvas backend:

http://gnuplot.sourceforge.net/demo_canvas/

(notice the coordinates at the bottom of the plot).

Jason

William Stein

unread,
Sep 14, 2009, 8:33:30 PM9/14/09
to sage-s...@googlegroups.com
On Mon, Sep 14, 2009 at 1:26 PM, Eric Jackson <eri...@comcast.net> wrote:
>
> I'm not thinking of matplotlib html5.  However, I am fairly new to
> working with Sage.  I will do some research to see what matplotlib
> html5 is about.
>
> As far as what I'm doing, I've created a plot of a function, say sin
> (t) that is evaluated from  t, -2*pi,2*pi.  As I am viewing the plot,
> I would like to move my cursor along the sin(t) curve and in real time
> see what the xy coordinates are at various locations on the curve.
>
> Eric

I think the easiest way to do this would be with javascript, and a
careful knowledge of how matplotlib coordinates correspond to png
image coordinates.

William

Jason Grout

unread,
Sep 14, 2009, 9:31:12 PM9/14/09
to sage-s...@googlegroups.com


You can get the transform that describes the display pixel -> data
coordinates straight from matplotlib. We could ship that to the browser
with the plot, then the browser could do the matrix multiplication on
its own.

See http://matplotlib.sourceforge.net/users/transforms_tutorial.html

In particular,

"You can use the inverted() method to create a transform which will take
you from display to data coordinates:

In [41]: inv = ax.transData.inverted()

In [42]: type(inv)
Out[42]: <class 'matplotlib.transforms.CompositeGenericTransform'>

In [43]: inv.transform((335.175, 247.))
Out[43]: array([ 5., 0.])


It would also be useful to peruse the definition of the transformation
pipeline:
http://matplotlib.sourceforge.net/users/transforms_tutorial.html#the-transformation-pipeline

Jason

--
Jason Grout

Jason Grout

unread,
Sep 15, 2009, 6:18:03 PM9/15/09
to sage-s...@googlegroups.com


Here's an example of the matplotlib canvas backend:

http://dl.getdropbox.com/u/178748/mpl/test.html

(it doesn't have the coordinate tracking feature implemented, I think).

Jason

--
Jason Grout

Eric Jackson

unread,
Sep 23, 2009, 3:35:17 PM9/23/09
to sage-support
To address my dilemma regarding line plots, I read about matplotlib at
http://matplotlib.sourceforge.net/users/transforms_tutorial.html.
This is a library that a user can import into their Sage worksheet to
allow then more flexibility with plots. When using matplotlib, the
user may have to apply certain backends to achieve visibility of
plots. The backend the user applies depends solely on where he/she is
using matplotlib interactively from.

A few minutes ago I published a sage worksheet called "Line Plot with
Matplotlib". Cell 1 of this sheet shows a simple plot using a
hardcopy backend to create a PNG file. This is an item that Jason
Grout helped me with. Thanks Jason! Cell 2 (#Their version from
matplotlib documentation) uses pylab instead of pyplot. The code in
cell 2 was obtained from the matplotlib website. I could not get this
to work, instead I inserted my own version in cell 3 (#My version),
which produces the same plot that cell 2 would produce had it worked.
If anybody can get cell 2 working, then that would be really cool.

*However, the code in cell 4, is where I really need the help. The
code in cell 4 is suppose to display the xy data at a certain location
on the line plot. I have looked at this for a while, but I am
confused as to why it doesn't work. This code was also taken from the
mathplotlib website. Any help on this in particular would be neat.
In my spare time, I will continue to work on this.

Thanks,
Eric

Jason Grout

unread,
Sep 23, 2009, 5:13:51 PM9/23/09
to sage-s...@googlegroups.com
Eric Jackson wrote:
> To address my dilemma regarding line plots, I read about matplotlib at
> http://matplotlib.sourceforge.net/users/transforms_tutorial.html.
> This is a library that a user can import into their Sage worksheet to
> allow then more flexibility with plots. When using matplotlib, the
> user may have to apply certain backends to achieve visibility of
> plots. The backend the user applies depends solely on where he/she is
> using matplotlib interactively from.
>
> A few minutes ago I published a sage worksheet called "Line Plot with
> Matplotlib". Cell 1 of this sheet shows a simple plot using a
> hardcopy backend to create a PNG file. This is an item that Jason
> Grout helped me with. Thanks Jason! Cell 2 (#Their version from
> matplotlib documentation) uses pylab instead of pyplot. The code in
> cell 2 was obtained from the matplotlib website. I could not get this
> to work, instead I inserted my own version in cell 3 (#My version),
> which produces the same plot that cell 2 would produce had it worked.
> If anybody can get cell 2 working, then that would be really cool.

You can't use "show". Use "savefig", as in:

savefig('test.png')

The sage notebook automatically displays any graphic file you generate
in a cell. That's why we need to save the figure to a graphics file,
like test.png. Then the notebook comes along, sees that the cell
generated a graphic file, and displays it.


>
> *However, the code in cell 4, is where I really need the help. The
> code in cell 4 is suppose to display the xy data at a certain location
> on the line plot. I have looked at this for a while, but I am
> confused as to why it doesn't work. This code was also taken from the
> mathplotlib website. Any help on this in particular would be neat.
> In my spare time, I will continue to work on this.


Just change the last line to "plt.savefig..." just like the first cell.
It's not "savefile", it's "savefig" :).


Thanks,

Jason

Eric Jackson

unread,
Sep 23, 2009, 7:56:57 PM9/23/09
to sage-s...@googlegroups.com
Thanks, I just figured this out right after I posted. This should
have been obvious, I guess I got brain tired.

Thanks again,
Eric
Reply all
Reply to author
Forward
0 new messages