Getting the set of point actually plotted (from Sage)

Hello all !

I'm sorry if my question is not clear, but I do not know ho to produce a simple example.

I'm plotting the graph of an implicit given function (say x^2+y^2=3) using Sage.

What I know it that
1. when I ask sage to plot implicit_plot( f==3,(x,-5,5),(y,-5,5) ),
     Sage computes f-3 on an array of points in the square (-5,-5)x(5,5).
2. Sage creates an object matplotlib.figure.Figure that contains somewhere the information about the array of computed points and ask matplotlib to plot it

What I understood is that somewhere in matplotlib, the values are parsed and a path is created. That path is the set of points on which f-3=0

My aim : catch the set of points that satisfy f-3=0. That has to be stored --or at last computed-- somewhere in matplotlib.figure.Figure

I read the source, but I'm really lost.

The final purpose is to know the bounding box of the points that are *actually* plotted without taking into account the axes, labels and other decorations.

Does someone know how to do that ?

Since the object I have on hand is created by Sage[1] in a quite complex way, I'm sorry to not being able to furnish an example.

Thanks
Laurent

If it can help, I have the following in a Sage terminal :

sage: var('x,y')
sage: F=implicit_plot(x**2+y**2==2,(x,-5,5),(y,-5,5),plot_points=100)
sage: F.matplotlib()
<matplotlib.figure.Figure object at 0xbfb60ac>
sage: F.matplotlib().get_children()
[<matplotlib.patches.Rectangle object at 0xc144e4c>, <matplotlib.axes.AxesSubplot object at 0xc14472c>]

I really do not understand where is the data ??? In the Rectangle ? In the Axes ?

On the Sage's side, the discussion is here :
http://ask.sagemath.org/question/359/get_minmax_data-on-implicit_plot

[1] www.sagemath.org

Your data are embedded in a Line2d object which is itself a child of an
Axes, itself child of the figure. Try:
Fig = F.matplotlib()
ax = Fig.get_axes()[0] # to get the first (and maybe only) subplot
line = ax.get_axes()[0]
xdata = line.get_xdata()
ydata = line.get_ydata()

···

Le dimanche 06 février 2011 à 14:29 +0100, Laurent a écrit :

If it can help, I have the following in a Sage terminal :

sage: var('x,y')
sage: F=implicit_plot(x**2+y**2==2,(x,-5,5),(y,-5,5),plot_points=100)
sage: F.matplotlib()
<matplotlib.figure.Figure object at 0xbfb60ac>
sage: F.matplotlib().get_children()
[<matplotlib.patches.Rectangle object at 0xc144e4c>,
<matplotlib.axes.AxesSubplot object at 0xc14472c>]

I really do not understand where is the data ??? In the Rectangle ? In
the Axes ?

--
Fabrice Silva

Your data are embedded in a Line2d object which is itself a child of an
Axes, itself child of the figure. Try:
Fig = F.matplotlib()
ax = Fig.get_axes()[0] # to get the first (and maybe only) subplot
line = ax.get_axes()[0]
xdata = line.get_xdata()
ydata = line.get_ydata()

There is something wrong ...

sage: var('x,y')

(x, y)
sage: F=implicit_plot(x**2+y**2==1,(x,-5,5),(y,-5,5))
sage: Fig = F.matplotlib()
sage: ax = Fig.get_axes()[0] <-- I checked : it is the only element :slight_smile:
sage: line = ax.get_axes()[0]

···

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)

TypeError: 'AxesSubplot' object does not support indexing

sage:line=ax.get_axes()

sage:type(line)

<class 'matplotlib.axes.AxesSubplot'>

However, using some "grep get_ydata" from that point, I suceed to track my information.
It was in the segments argument of matplotlib.collections.LineCollection

Now I'm tracking back the information ... It is in
mcontour.QuadContourSet(self, *args, **kwargs).allsegs
in the method matplotlib.axes.Axes.contour()

I'm almost done.

Thanks for help !

Have a nice afternoon
Laurent

PS :
I'll post the final answer here :

PPS :
Argh !! Someone already did !