Python ProgrammingPython Programming

How to create square Bubble Plot using Numpy and Matplotlib?

Square Bubble Plot

import matplotlib.pyplot as plt
import numpy as np
import random

xs = np.arange(1, 5, 1)
ys = np.arange(0.5, 6, 1)

colors = ["red", "blue", "green"]


def square_size_color(value):

    square_color = random.choice(colors)

    if value < 1:
        square_size = random.choice(range(1, 10))
    if 3 > value > 1:
        square_size = random.choice(range(10, 25))
    else:
        square_size = random.choice(range(25, 35))

    return square_size, square_color


for x in xs:
    for y in ys:
        square_size, square_color = square_size_color(y)
        plt.plot(x, y, linestyle="None", marker="s",
                 markersize=square_size, mfc=square_color, mec=square_color)

plt.grid(visible=True, axis='y')
plt.xlim(0.5, 4.5)
plt.ylim(-0.5, 6.5)
plt.show()

The following is the output that will be obtained:


How to create square Bubble Plot using Numpy and Matplotlib?