<jupyter_start><jupyter_text>With bounded Lloyd relaxation<jupyter_code>def apply_bounded_lloyd_relaxation(points, boundary, iterations=5):
    points_to_use = points.copy()

    for i in range(iterations):
        vor = Voronoi(np.vstack([points_to_use, boundary]))
        relevant_regions = vor.regions
        relevant_regions = [a for a in relevant_regions if (-1 not in a) and len(a) > 0]
        relevant_regions = [vor.regions[x] for x in vor.point_region[:len(points)]]  # Beta code
        regions_coordinates = [np.vstack([vor.vertices[x] for x in region]) for region in relevant_regions]
        region_centroids = np.array([Polygon(region).centroid.bounds[:2] for region in regions_coordinates])
        points_to_use = region_centroids

    return(points_to_use)


# plot A
# plt.plot(np.array(A.boundary.coords.xy).T[:,0], np.array(A.boundary.coords.xy).T[:,1], color=(0.855,0.314,0.196,1.0))
# plt.gca().add_patch(Circle((a_x, a_y), a_r, zorder=0, lw=2, edgecolor=(0.855,0.314,0.196,1.0), color=(0.855,0.314,0.196,.3)))
# plt.text(0,2.3,"Spanish", ha='center', color=(.36,.36,.36))

# plot B
plt.plot(np.array(B.boundary.coords.xy).T[:,0], np.array(B.boundary.coords.xy).T[:,1], color=(0.855,0.314,0.196,1.0))
plt.gca().add_patch(Circle((b_x, b_y), b_r, zorder=0, lw=2, edgecolor=(0.855,0.314,0.196,1.0), color=(0.855,0.314,0.196,.3)))
plt.text(-1.6,-0.6,"Besu", ha='right', color=(.36,.36,.36))

# plot C
plt.plot(np.array(C.boundary.coords.xy).T[:,0], np.array(C.boundary.coords.xy).T[:,1], color=(0.855,0.314,0.196,1.0))
plt.gca().add_patch(Circle((c_x, c_y), c_r, zorder=0, lw=2, edgecolor=(0.855,0.314,0.196,1.0), color=(0.855,0.314,0.196,0.3)))
plt.text(1.6,-0.6,"Teku", ha='left', color=(.36,.36,.36))


# Plot the population

rand_x_range = (-2,2)
rand_y_range = (-1.5,2.5)
scatter_kwargs = {'color': (.36,.36,.36),
                  's': 5}



# Plot just A
# points = random_points_within(A.difference(B).difference(C), just_a)
# boundary = A.difference(B).difference(C).boundary
# boundary_coordinates = np.array(boundary.coords.xy).T
# relaxed_points = apply_bounded_lloyd_relaxation(points, boundary_coordinates, iterations=100)
# plt.scatter(relaxed_points[:,0], relaxed_points[:,1], **scatter_kwargs)         
            

# plot just B
points = random_points_within(B.difference(C), just_b)
boundary = B.difference(C).boundary
boundary_coordinates = np.array(boundary.coords.xy).T
relaxed_points = apply_bounded_lloyd_relaxation(points, boundary_coordinates, iterations=190)
plt.scatter(relaxed_points[:,0], relaxed_points[:,1], **scatter_kwargs)         
            
            
# plot just C
points = random_points_within(C.difference(B), just_c)
boundary = C.difference(B).boundary
boundary_coordinates = np.array(boundary.coords.xy).T
relaxed_points = apply_bounded_lloyd_relaxation(points, boundary_coordinates, iterations=190)
plt.scatter(relaxed_points[:,0], relaxed_points[:,1], **scatter_kwargs)            


# plot A ^ B
# points = random_points_within(A.intersection(B).difference(C), a_intersection_b)
# boundary = A.intersection(B).difference(C).boundary
# boundary_coordinates = np.array(boundary.coords.xy).T
# relaxed_points = apply_bounded_lloyd_relaxation(points, boundary_coordinates, iterations=100)
# plt.scatter(relaxed_points[:,0], relaxed_points[:,1], **scatter_kwargs)
            
# plot A ^ C
# points = random_points_within(A.intersection(C).difference(B), a_intersection_c)
# boundary = A.intersection(C).difference(B).boundary
# boundary_coordinates = np.array(boundary.coords.xy).T
# relaxed_points = apply_bounded_lloyd_relaxation(points, boundary_coordinates, iterations=190)
# plt.scatter(relaxed_points[:,0], relaxed_points[:,1], **scatter_kwargs)
            
# plot B ^ C
points = random_points_within(B.intersection(C), b_intersection_c)
boundary = B.intersection(C).boundary
boundary_coordinates = np.array(boundary.coords.xy).T
relaxed_points = apply_bounded_lloyd_relaxation(points, boundary_coordinates, iterations=190)
plt.scatter(relaxed_points[:,0], relaxed_points[:,1], **scatter_kwargs)


# plot A ^ B ^ C
# points = random_points_within(A.intersection(B).intersection(C), a_intersection_b_intersection_c)
# boundary = A.intersection(B).intersection(C).boundary
# boundary_coordinates = np.array(boundary.coords.xy).T
# relaxed_points = apply_bounded_lloyd_relaxation(points, boundary_coordinates, iterations=100)
# plt.scatter(relaxed_points[:,0], relaxed_points[:,1], **scatter_kwargs)
            

# Fine tune the presentation of the graph
plt.axes().set_aspect('equal', 'datalim')
plt.gca().axis('off')
plt.xlim(-3.5,3.5)
plt.ylim(-1.5,2.5)
plt.gcf().set_size_inches(6,5)
# plt.title('A level subjects chosen', color=(.36,.36,.36))

# Save the output
# plt.savefig('Venn.png', dpi=600)
plt.savefig("Venn.svg")<jupyter_output>/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:8: UserWarning: Setting the 'color' property will override the edgecolor or facecolor properties.
  
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:13: UserWarning: Setting the 'color' property will override the edgecolor or facecolor properties.
  del sys.path[0]
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:81: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
{'fraction_non_alphanumeric': 0.15689810640216412, 'fraction_numerical': 0.04472497745716862, 'mean_word_length': 5.338285714285714, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '506608', 'license': 'MIT', 'n_tokens_mistral': 2181, 'n_tokens_neox': 1988, 'n_words': 338, 'path': 'python_notebooks/src/populated_venn_diagram.ipynb', 'repo_name': 'cesarsotovalero/ethereum-ssc', 'size': '5545'}