import mpld3 from mpld3 import plugins from mpld3.utils import get_id import numpy as np import collections import matplotlib.pyplot as plt N_paths = 5 N_steps = 100 x = np.linspace(0, 10, 100) y = 0.1 * (np.random.random((N_paths, N_steps)) - 0.5) y = y.cumsum(1) fig, ax = plt.subplots() labels = ["a", "b", "c", "d", "e"] line_collections = ax.plot(x, y.T, lw=4, alpha=0.2) interactive_legend = plugins.InteractiveLegendPlugin(line_collections, labels) plugins.connect(fig, interactive_legend) mpld3.display() N_paths = 5 N_steps = 100 x1 = np.linspace(0, 10, 100) y = 0.1 * (np.random.random((N_paths, N_steps)) - 0.5) y1 = y.cumsum(1) x2 = np.linspace(0, 10, 100) y = 0.1 * (np.random.random((N_paths, N_steps)) - 0.5) y2 = y.cumsum(1) fig, ax = plt.subplots() labels = ["a", "b",] l1 = ax.plot(x1, y1.T, lw=4, alpha=0.1, c='b', label='a') l2 = ax.plot(x2, y2.T, lw=4, alpha=0.2, c='r', label='b') line_collections = [l1,l2] plugins.connect(fig, plugins.InteractiveLegendPlugin(line_collections, labels)) mpld3.display() N_paths = 5 N_steps = 100 x = np.linspace(0, 10, 100) y = 0.1 * (np.random.random((N_paths, N_steps)) - 0.5) y = y.cumsum(1) fig = plt.figure() ax1 = fig.add_subplot(2,1,1) ax2 = fig.add_subplot(2,1,2) labels = ["a", "b", "c", "d", "e"] l1 = ax1.plot(x, y.T, lw=4, alpha=0.1) s1 = [] for i in range(N_paths): s = ax2.scatter(x,y[i, :], c=next(ax2._get_lines.color_cycle), alpha=0.1) s1.append(s) plugins.connect(fig, plugins.InteractiveLegendPlugin(l1, labels, ax=ax1)) plugins.connect(fig, plugins.InteractiveLegendPlugin(s1, labels, ax=ax2)) mpld3.display() N_paths = 5 N_steps = 100 x = np.linspace(0, 10, 100) y = 0.1 * (np.random.random((N_paths, N_steps)) - 0.5) y = y.cumsum(1) fig = plt.figure() ax1 = fig.add_subplot(2,1,1) ax2 = fig.add_subplot(2,1,2) labels = ["a", "b", "c", "d", "e"] l1 = ax1.plot(x, y.T, lw=4, alpha=0.1) s1 = [] for i in range(N_paths): s = ax2.scatter(x,y[i, :], c=next(ax2._get_lines.color_cycle), alpha=0.1) s1.append(s) plugins.connect(fig, plugins.InteractiveLegendPlugin(zip(l1, s1), labels)) mpld3.display() nr_elements = 5 fig, ax = plt.subplots() elements = [] for i in range(nr_elements): x = np.random.rand(100) y = np.random.rand(100) element = ax.scatter(x,y, color=next(ax2._get_lines.color_cycle), alpha=0.2, marker='+') elements.append([element]) labels = ["{}".format(i) for i in range(nr_elements)] plugins.connect(fig, plugins.InteractiveLegendPlugin(elements, labels)) mpld3.display() N_paths = 5 N_steps = 100 x = np.linspace(0, 10, 100) y = 0.1 * (np.random.random((N_paths, N_steps)) - 0.5) y = y.cumsum(1) fig = plt.figure() ax1 = fig.add_subplot(2,1,1) ax2 = fig.add_subplot(2,1,2) labels = ["a", "b", "c", "d", "e"] l1 = ax1.plot(x, y.T, marker='x',lw=2, alpha=0.1) s1 = ax2.plot(x, y.T, 'o', ms=8, alpha=0.1) plugins.connect(fig, plugins.InteractiveLegendPlugin(zip(l1, s1), labels)) mpld3.display()