7 Sample - Notebook - With - Code - Cells
7 Sample - Notebook - With - Code - Cells
7 Sample - Notebook - With - Code - Cells
1.2 Now we will display cells with code and their output
[25]: # This cell imports some python packages and has no output
fig, ax = plt.subplots()
ax.plot(t, s)
fig.savefig("test.png")
1
plt.show()
np.random.seed(19680801)
fig, ax = plt.subplots()
for color in ['tab:blue', 'tab:orange', 'tab:green']:
n = 750
x, y = np.random.rand(2, n)
scale = 200.0 * np.random.rand(n)
ax.scatter(x, y, c=color, s=scale, label=color,
alpha=0.3, edgecolors='none')
ax.legend()
ax.grid(True)
plt.show()
2
1.2.2 A plot with subfigures ans complicated alignment of labels and tags
fig = plt.figure(tight_layout=True)
gs = gridspec.GridSpec(2, 2)
ax = fig.add_subplot(gs[0, :])
ax.plot(np.arange(0, 1e6, 1000))
ax.set_ylabel('YLabel0')
ax.set_xlabel('XLabel0')
for i in range(2):
ax = fig.add_subplot(gs[1, i])
ax.plot(np.arange(1., 0., -0.1) * 2000., np.arange(1., 0., -0.1))
ax.set_ylabel('YLabel1 %d' % i)
ax.set_xlabel('XLabel1 %d' % i)
if i == 0:
for tick in ax.get_xticklabels():
tick.set_rotation(55)
fig.align_labels() # same as fig.align_xlabels(); fig.align_ylabels()
plt.show()
3
1.2.3 A python cell with printed ouput and formatted in different ways
return raw_string
[29]: an_oak(2,"$\theta$'s")
[30]: display(Latex(an_oak(2,"$\theta$'s")))
4
We have 2 of these awesome θ’s
[32]: display(Latex(an_oak(2,r"$\\theta$'s")))