test_display.ipynb
336 lines
| 84.4 KiB
| text/plain
|
TextLexer
/ tests / test_display.ipynb
In [3]:
from IPython.core.displaypub import publish_display_data
%load_ext rmagic
publish_display_data('Assignment1', {'text/html':'<h2>Question 1</h2>'})
In [4]:
%%R
X = rnorm(40)
Y = rnorm(40)
plot(X,Y, pch=24, bg='red', cex=2)
In [5]:
publish_display_data('Assignment1',{'text/latex':r'''What is the correlation, $\rho$? We could also have plotted with matplotlib...'''})
In [6]:
import pylab
%Rpull X Y
pylab.scatter(X, Y, c='r')
pylab.gca().set_xlabel('X')
pylab.gca().set_ylabel('Y')
Out[6]:
In [7]:
publish_display_data('Assignment1',{'text/html':r'''We might include some other html stuff, too.
<iframe width="560" height="315" src="http://www.youtube.com/embed/sf49cw0134U"
frameborder="0" allowfullscreen></iframe>'''})
In [8]:
publish_display_data('Assignment1',{'text/html':'<h2>Answer</h2>'})
In [9]:
publish_display_data('Assignment', {'text/html': '''<input type="radio" name="group1" value="Milk"> Milk<br>
<input type="radio" name="group1" value="Butter" checked> Butter<br>'''})
Magics¶
In [10]:
run magics/homework.py
In [11]:
%%MultipleChoiceSetup 1
X = rnorm(200)
Y = rnorm(200)
plot(X,Y)
In [12]:
%%MultipleChoiceQuestion 1
question_text = 'Is the correlation:'
choices = ['positive', 'negative', 'zero']
In [23]:
%%MultipleChoiceSetup 2
X = rnorm(20)
Y = rnorm(20) + Y
print(summary(lm(Y~X)))
true_corr = cor(X,Y)
In [24]:
true_corr = %R cor(X,Y)
In [27]:
%%MultipleChoiceQuestion 2
question_text = r'Up to 1 significant digit, what is the correlation between $X$ and $Y$?'
while True:
choices = ['%0.1f' % c for c in list(np.random.random(size=(3,))*2-1) + [true_corr]]
if len(set(choices)) == 4 :
break
In [14]: