Python ProgrammingPython Programming

Plotting all available markers at random coordinates in Matplotlib

Plotting all available markers at random coordinates:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D

# Prepare 50 random numbers to plot
n1 = np.random.rand(50)
n2 = np.random.rand(50)

markerindex = np.random.randint(0, len(Line2D.markers), 50)

for x, y in enumerate(Line2D.markers):
    i = (markerindex == x)
    plt.scatter(n1[i], n2[i], marker=y)

plt.show()

The following is the output that will be obtained:


Plotting all available markers at random coordinates in Matplotlib