50 views

Skip to first unread message

Dec 14, 2011, 10:39:51 AM12/14/11

to sage-s...@googlegroups.com

Hello!

I have noticed a strange unpredictable behaviour of the "plot"

function today.

I have noticed a strange unpredictable behaviour of the "plot"

function today.

Here is the situation:

I have a data set in the following form:

[[2006, 289.575000000000],

[2007, 289.547000000000],

[2008, 289.479000000000],

[2009, 289.586000000000],

[2010, 289.620000000000]]

and a function to work with these data:

def dGT(t):

number = int(round(t))-temperature[0][0]

return round(temperature[number+1][1]- \

temperature[number][1],3)

Then I want to plot this function in some range. It turns out that the

result is more or less unpredictable. I simply do the following to test:

########## Plotting ##########

total_plot = plot(dGT, marker=".", xmin=2000, xmax=2010, color='blue',

plot_points=2010-2000+1, adaptive_recursion=0) total_plot += plot(dGT,

marker=".",xmin=2000, xmax=2010, color='red', plot_points=2010-2000+1,

adaptive_recursion=0) total_plot += plot(dGT, marker=".",xmin=2000,

xmax=2010, color='green', plot_points=2010-2000+1,

adaptive_recursion=0) total_plot += plot(dGT, marker=".",xmin=2000,

xmax=2010, color='cyan', plot_points=2010-2000+1, adaptive_recursion=0)

total_plot += plot(dGT, marker=".",xmin=2000, xmax=2010,

color='magenta', plot_points=2010-2000+1, adaptive_recursion=0)

total_plot += plot(dGT, marker=".",xmin=2000, xmax=2010,

color='yellow', plot_points=2010-2000+1, adaptive_recursion=0)

total_plot += plot(dGT, marker=".",xmin=2000, xmax=2010, color='black',

plot_points=2010-2000+1, adaptive_recursion=0)

total_plot.show(figsize=[10,4], gridlines='minor')

########## End Plotting ##########

The result looks very strange to me:

http://wombat.org.ua/plot-random-points.png

So my question is:

1. How does the "plot" function choose the exact points to use between

the starting and the ending points?

2. Is there a way to make it evaluate the function being plotted with a

certain step?

Thank you.

Vladimir

-----

<v_...@ukr.net>

Dec 14, 2011, 11:20:02 AM12/14/11

to sage-support

> Then I want to plot this function in some range. It turns out that the

> result is more or less unpredictable. I simply do the following to test:

>

> ########## Plotting ##########

> total_plot = plot(dGT, marker=".", xmin=2000, xmax=2010, color='blue',

> plot_points=2010-2000+1, adaptive_recursion=0)

> result is more or less unpredictable. I simply do the following to test:

>

> ########## Plotting ##########

> total_plot = plot(dGT, marker=".", xmin=2000, xmax=2010, color='blue',

> plot_points=2010-2000+1, adaptive_recursion=0)

Well, here you go. You did only 11 plot points and no "adaptive

recursion". As you can see at

http://sagemath.org/doc/reference/sage/plot/plot.html#sage.plot.plot.generate_plot_points,

if you do "randomize=False" you will get what you want.

> So my question is:

> 1. How does the "plot" function choose the exact points to use between

> the starting and the ending points?

You should be able to read the code in

sage.plot.plot.generate_plot_points?? and follow it for the precise

details; the adaptive process is pretty well documented at

http://sagemath.org/doc/reference/sage/plot/plot.html#sage.plot.plot.plot

- search for "the algorithm used to insert extra points is actually

pretty simple".

> 2. Is there a way to make it evaluate the function being plotted with a

> certain step?

I think this should work. Or you could use a list comprehension and

plot the points.

sage: f(x) = sin(x)

sage: L = [(i,f(i)) for i in srange(0,3,.5)]

sage: line(L)

- kcrisman

Dec 14, 2011, 12:07:13 PM12/14/11

to sage-s...@googlegroups.com

Hello!

On Wed, 14 Dec 2011 08:20:02 -0800 (PST)

kcrisman <kcri...@gmail.com> wrote:

>... As you can see at

> http://sagemath.org/doc/reference/sage/plot/plot.html#sage.plot.plot.generate_plot_points,

> if you do "randomize=False" you will get what you want.

>

Thanks a lot! It did exactly what I wanted to get!

Still, this solution is not obvious enough, because to benefit from

it, one must know that there is such function in the 'plot' module.

I must note that there are many similar recipes to make this or that

by doing

from something.something.something import something

and get the functions you want, but how can one get the information

that there IS such a function in this particular module?

Dec 14, 2011, 12:27:14 PM12/14/11

to sage-s...@googlegroups.com

In this case, reading the documentation for plot would have pointed you

in the right direction. You could do this by just typing "plot?" in

Sage, or I usually search using google: sage docs plot

I get this page: http://www.sagemath.org/doc/reference/sage/plot/plot.html

Then I click on the plot() command, and it talks about the adaptive

algorithm, and one of the first examples talks about the randomize

keyword. As for finding the exact function that generates the random

points, I would look at the source code for plot and trace the execution

of the function from there. You can see the source code for plot by

doing plot?? in Sage.

That said, we're always looking for ways to improve the documentation

and the discoverability of things. Patches are always welcome!

Thanks,

Jason

Dec 14, 2011, 7:35:23 PM12/14/11

to sage-s...@googlegroups.com

Perhaps you want list_plot, since you are plotting discrete points?

Dan

--

--- Dan Drake

----- http://mathsci.kaist.ac.kr/~drake

-------

Reply all

Reply to author

Forward

0 new messages

Search

Clear search

Close search

Google apps

Main menu