I am trying to code up a persistence diagram for points on a circle from scratch, more or less, I don't want to rely on any packages to construct the diagram for me. I have posted the code I have so far below, I have three issues that I would love to ask for help with.
Right now the code is outputting 11 different graphs, this was intentional for the time being, but I would love to animate the process, how might I go about editing the code I have to make this work?
There should be a death point on the persistence diagram at (0, .3) but it isn't showing up on the graph, I cannot for the life of me figure out why that might be happening, does anyone spy an issue or a bug there?
Lastly, I would like to have the graphs stacking on top of one another as they print out, that is I would like the points on the persistence diagram to stack with each consecutive image. However, right now the code is written in a way that a new graph is being produced with each iteration, is there a way that I can fix this and stack the points on consecutive graphs? Animating the output might take care of this issue but I am new to coding in Python and would love to know how I would do this anyway for future reference.
Any help here is greatly appreciated! Here is my code:
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import numpy as np
# settings for the circle
r = 1 # radius
h = 0 # x-coord of center
k = 0 # y-coord of center
# a randomly determined selection of angles
theta = np.array( [1 * np.pi / 6, 2 * np.pi / 3, 4 * np.pi / 5,
1 * np.pi / 5, 2 * np.pi / 5, 4 * np.pi / 7,
1 * np.pi / 4, 2 * np.pi / 9, 4 * np.pi / 3,
1 * np.pi / 3, 3 * np.pi / 2, 5 * np.pi / 9,
1 * np.pi / 2, 3 * np.pi / 8, 5 * np.pi / 4,
1 * np.pi / 1, 3 * np.pi / 7, 5 * np.pi / 3] )
# calculating coordinates
x = h + r * np.cos(theta)
y = k + r * np.sin(theta)
# plot the graph
list = np.linspace(0,1,11) # vector of increasing radii
death_list = np.array( (.1, .2, .3, .4, .8) ) # list of radii that cause deaths
for i in list :
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.scatter(x,y, color = "green", marker = "o", s = 15)
for xx,yy in zip(x,y) :
cir = mpatches.Circle((xx, yy), i, color='r',fill=True, zorder = 0)
ax1.add_patch(cir)
ax1.set_aspect('equal', adjustable='datalim')
ax1.set_title('Random Points on a Circle')
ax1.set(xlabel='x-axis', ylabel='y-axis')
ax1.set_xlim([-1.25, 1.25])
ax1.set_ylim([-1.25, 1.25])
a = np.arange(0,1.1,.1)
b = a
ax2.plot(a,b)
ax2.axhline(y = i, label = 'current radius = ', color = 'r', linestyle = '-')
if i in death_list :
ax2.plot(0, i , marker="o", markersize=5, markeredgecolor="green", markerfacecolor="green")
ax2.legend(loc = 'lower right')
ax2.set_aspect('equal', adjustable='datalim')
ax2.set_title('Persistence Diagram')
ax2.set(xlabel='Birth', ylabel='Death')
fig.set_figheight(5)
fig.set_figwidth(10)
plt.show()