ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 20 Mar 2012 09:15:05 -0500how to enter a list of data points in an interact?http://ask.sagemath.org/question/8799/how-to-enter-a-list-of-data-points-in-an-interact/I want to enter a default list of (x,y) data for a scatter plot that the user can modify to create a different scatter plot.Tue, 20 Mar 2012 06:15:02 -0500http://ask.sagemath.org/question/8799/how-to-enter-a-list-of-data-points-in-an-interact/Answer by Shashank for <p>I want to enter a default list of (x,y) data for a scatter plot that the user can modify to create a different scatter plot.</p>
http://ask.sagemath.org/question/8799/how-to-enter-a-list-of-data-points-in-an-interact/?answer=13379#post-id-13379I am not sure how exactly you want to do this but let me know whether this is what you want. User can change the array and unfocus from the input box to update.
@interact
def int_plot(str1 = input_box('[[1,2],[3,5],[4,2]]',type = str, label='array 1: ')):
array1=eval(str1)
scatter_plot(array1).show()
![image description](/upfiles/13322611708674591.png)
Tue, 20 Mar 2012 06:34:20 -0500http://ask.sagemath.org/question/8799/how-to-enter-a-list-of-data-points-in-an-interact/?answer=13379#post-id-13379Comment by dasmith88 for <p>I am not sure how exactly you want to do this but let me know whether this is what you want. User can change the array and unfocus from the input box to update.</p>
<pre><code>@interact
def int_plot(str1 = input_box('[[1,2],[3,5],[4,2]]',type = str, label='array 1: ')):
array1=eval(str1)
scatter_plot(array1).show()
</code></pre>
<p><img alt="image description" src="/upfiles/13322611708674591.png"/></p>
http://ask.sagemath.org/question/8799/how-to-enter-a-list-of-data-points-in-an-interact/?comment=20096#post-id-20096Yes, it's perfect. For the record, here's the code with a few bells and whistles added.
@interact def int_plot(t1=text_control("Enter data as a list of pairs, and set window [a,b] by [c,d]."), str1 = input_box('[[1975,4123], [1980,3851], [1985,3461], [1990,2827], [1995,2515], [2000, 2092]]',type = str, label='data '), a = (1970), b = (2000), c = (2000), d = (4500) , xlabel= ('Year'), ylabel= ('Consumption')):
array1=eval(str1)
s=scatter_plot(array1, xmin=a, xmax = b, ymin=c, ymax=d, figsize=6, axes_labels=[str(xlabel),str(ylabel)])
show(s)Tue, 20 Mar 2012 09:15:05 -0500http://ask.sagemath.org/question/8799/how-to-enter-a-list-of-data-points-in-an-interact/?comment=20096#post-id-20096Comment by dasmith88 for <p>I am not sure how exactly you want to do this but let me know whether this is what you want. User can change the array and unfocus from the input box to update.</p>
<pre><code>@interact
def int_plot(str1 = input_box('[[1,2],[3,5],[4,2]]',type = str, label='array 1: ')):
array1=eval(str1)
scatter_plot(array1).show()
</code></pre>
<p><img alt="image description" src="/upfiles/13322611708674591.png"/></p>
http://ask.sagemath.org/question/8799/how-to-enter-a-list-of-data-points-in-an-interact/?comment=20097#post-id-20097That looks like what I need -- thanks. I'll let you know how it works when I adapt it.Tue, 20 Mar 2012 08:05:05 -0500http://ask.sagemath.org/question/8799/how-to-enter-a-list-of-data-points-in-an-interact/?comment=20097#post-id-20097