In jupyter, you must explicitly designate a cell as markdown - by default, cells are code.
First, we'll import numpy for mathematical calculations and matplotlib's pyplot for plotting.
import numpy as np
import matplotlib.pyplot as plt
The logarithmic spiral has a polar equation of $$r = a e^{b\theta}$$ where $r$ is distance from the origin, $\theta$ is the angle from the x-axis, and $a$ and $b$ are constants. Source
We can write the logarithmic spiral equation in Cartesian coordinates as: $$\begin{array} x &= r \cos\theta = a \cos\theta e^{b\theta}\\y &= r \sin\theta = a \sin\theta e^{b\theta}\end{array}$$
We can implement this spiral in R by first defining it in polar coordinates and then converting the polar coordinates into a sequence of Cartesian points that should be connected by line segments.
# Define the angle of the spiral (polar coords)
# go around two full times (2*pi = one revolution)
theta = np.arange(0, 4 * np.pi, 0.01)
# Define the distance from the origin of the spiral
# Needs to have the same length as theta
# (get length of theta with theta.size,
# and then divide 5 by that to get the increment)
r = np.arange(0, 5, 5/theta.size)
# Now define x and y in cartesian coordinates
x = r * np.cos(theta)
y = r * np.sin(theta)
I'm less familiar with plotting in python than I am in R, but this code seems to work to generate the same type of plot:
# Define the axes
fig, ax = plt.subplots()
# Plot the line
ax.plot(x, y)
plt.show()
The same type of markdown formatting works in jupyter notebooks as well:
With markdown, I can create nice formatting with simple text -
A really nice quote
some code from an unknown language
I also like the ability to make
but sometimes you want to make a
I have to put a blank line between the text and the list for the formatting to work just right. When in doubt, add a blank line :).