Created
March 16, 2023 08:34
-
-
Save singularitti/48994adad53431a8ec5adc4b78e431ee to your computer and use it in GitHub Desktop.
Bubble Plot Generator using ChatGPT #GPT #Python #plotting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import random | |
| # Generate random colors | |
| def random_color(): | |
| return [random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1)] | |
| # Generate coordinates for small bubbles around a big bubble with a fixed distance | |
| def small_bubbles(x, y, radius, distance, num_bubbles, min_radius, max_radius): | |
| angle = np.linspace(0, 2 * np.pi, num_bubbles) + np.random.rand(num_bubbles) / 2 | |
| small_bubbles = [] | |
| for a in angle[0:-1]: | |
| r = random.uniform(min_radius, max_radius) | |
| x_offset = (radius + distance) * np.cos(a) | |
| y_offset = (radius + distance) * np.sin(a) | |
| small_bubbles.append((x + x_offset, y + y_offset, r)) | |
| return small_bubbles | |
| # Set random seed for reproducibility | |
| random.seed(42) | |
| # Create a new figure | |
| fig, ax = plt.subplots() | |
| # Generate big bubbles | |
| num_big_bubbles = 6 | |
| big_bubbles = [] | |
| big_bubble_radius = 0.05 | |
| for i in range(num_big_bubbles): | |
| x = 0.5 + 0.3 * np.cos(2 * np.pi * i / num_big_bubbles) | |
| y = 0.5 + 0.3 * np.sin(2 * np.pi * i / num_big_bubbles) | |
| color = random_color() | |
| big_bubbles.append((x, y, big_bubble_radius, color)) | |
| # Generate and plot small bubbles around the big bubbles | |
| for big_bubble in big_bubbles: | |
| x, y, radius, color = big_bubble | |
| num_small_bubbles = random.randint(5, 8) | |
| distance = 1.1 * radius | |
| min_radius = 0.01 | |
| max_radius = 0.03 | |
| small_bubbles_coords = small_bubbles(x, y, radius, distance, num_small_bubbles, min_radius, max_radius) | |
| for small_bubble in small_bubbles_coords: | |
| x_small, y_small, radius_small = small_bubble | |
| circle = plt.Circle((x_small, y_small), radius_small, color=color, alpha=0.5) | |
| ax.add_artist(circle) | |
| # Add an arrow pointing from the small bubble to the big bubble | |
| arrow = plt.Arrow(x, y, x_small - x, y_small - y, color=color, alpha=0.5, width=0.02) | |
| ax.add_artist(arrow) | |
| # Plot big bubble | |
| circle = plt.Circle((x, y), radius, color=color, alpha=1) | |
| ax.add_artist(circle) | |
| # Set axis limits and aspect ratio | |
| ax.set_xlim(0, 1) | |
| ax.set_ylim(0, 1) | |
| ax.set_aspect('equal', adjustable='box') | |
| # Remove frames, ticks, and labels | |
| plt.axis('off') | |
| # Show the plot | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My instruction was: