Skip to main content

One post tagged with "hola"

View All Tags

First Blog Post

· One min read
Frank Zickert
Frank from PyQML

Equations

Use the MyST directive referenced in :

ψ=cosθ20+sinθ21=[cosθ2sinθ2]|\psi\rangle = cos\frac{\theta}{2}|0\rangle+sin\frac{\theta}{2}|1\rangle= \begin{bmatrix}cos\frac{\theta}{2}\\sin\frac{\theta}{2}\end{bmatrix}

Admonitions

see the Docusaurus reference for how to admonitions

tip

Try changing tip to warning!

Rendered Images

Use matplotlib to create images

TODO: how to reference an output image?!

# the next cell

from IPython.display import Math
Math(r"\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}")

:::embed #my-cell :::

from base64 import b64decode
from io import BytesIO

from IPython import get_ipython
from IPython.core.magic import register_cell_magic
import PIL


@register_cell_magic
def capture_png(line, cell):
get_ipython().run_cell_magic(
'capture',
' --no-stderr --no-stdout result',
cell
)
out_paths = line.strip().split(' ')
for output in result.outputs:
data = output.data
if 'image/png' in data:
path = out_paths.pop(0)
if not path:
raise ValueError('Too few paths given!')
png_bytes = data['image/png']
if isinstance(png_bytes, str):
png_bytes = b64decode(png_bytes)
assert isinstance(png_bytes, bytes)
bytes_io = BytesIO(png_bytes)
image = PIL.Image.open(bytes_io)
image.save(path, 'png')
%%capture_png test_copy.png
import numpy as np
import matplotlib.pyplot as plt

time = np.arange(0, 10, 0.1);
amplitude = np.sin(time)

with plt.xkcd():


plt.plot(time, amplitude)
plt.title('Sine wave')
plt.xlabel('Time')
plt.ylabel('Amplitude = sin(time)')
plt.axhline(y = 0, color ='k')

plt.show()