0% found this document useful (0 votes)
16 views5 pages

7 Sample - Notebook - With - Code - Cells

The document provides examples of different types of plots that can be created in Python including line plots, scatter plots, and subplots. It also demonstrates formatting output from Python cells for export to HTML and PDF including displaying latex equations. The examples cover a range of plotting and formatting techniques.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views5 pages

7 Sample - Notebook - With - Code - Cells

The document provides examples of different types of plots that can be created in Python including line plots, scatter plots, and subplots. It also demonstrates formatting output from Python cells for export to HTML and PDF including displaying latex equations. The examples cover a range of plotting and formatting techniques.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Sample_notebook

September 15, 2021

1 Notebook with some example fields to be exported to pdf and


HTML

1.1 Below some plain markdown cells examples

This is a standard markdown cell.


∫b
This is a standard markdown cell with some latex in it. There is inline latex a f (x)dx as well as
displayed
∫ b
f (x)dx
a

1.2 Now we will display cells with code and their output

[25]: # This cell imports some python packages and has no output

import matplotlib.pyplot as plt


import numpy as np
import matplotlib.gridspec as gridspec
from IPython.display import display, Math, Latex

### A simple plot using matplotlib


[3]: #First plot

# Data for plotting


t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)

fig, ax = plt.subplots()
ax.plot(t, s)

ax.set(xlabel='time (s)', ylabel='voltage (mV)',


title='About as simple as it gets, folks')
ax.grid()

fig.savefig("test.png")

1
plt.show()

1.2.1 A scatter plot

[5]: # Second plot

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

[7]: # Third plot

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

[17]: def an_oak(float_variable, string_variable):

raw_string = f"We have {float_variable} of these awesome {string_variable}"

return raw_string

Output the string directly


[18]: an_oak(2,"Potatos")

[18]: 'We have 2 of these awesome Potatos'

[29]: an_oak(2,"$\theta$'s")

[29]: "We have 2 of these awesome $\theta$'s"

[30]: display(Latex(an_oak(2,"$\theta$'s")))

We have 2 of these awesome heta’s


[31]: display(Latex(an_oak(2,"$\\theta$'s")))

4
We have 2 of these awesome θ’s
[32]: display(Latex(an_oak(2,r"$\\theta$'s")))

We have 2 of these awesome


theta’s
[33]: display(Latex(an_oak(2,r"$\theta$'s")))

We have 2 of these awesome θ’s

You might also like