Skip to article frontmatterSkip to article content

Matplotlib

Using ipywidgets and matplotlib directly in your browser

%pip install ipywidgets
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import interact, interactive
from IPython.display import display

import numpy as np

from matplotlib import pyplot as plt

def plot(colormap):

    fig = plt.figure()
    n = 100_000
    x = np.random.standard_normal(n)
    y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)
    xlim = x.min(), x.max()
    ylim = y.min(), y.max()

    ax0 = plt.axes()

    hb = plt.hexbin(x, y, gridsize=50, bins='log', cmap=colormap)
    ax0.set(xlim=xlim, ylim=ylim)
    ax0.set_title("With a log color scale")
    fig.colorbar(hb, ax=ax0, label='log10(N)')
    plt.show()
w = interactive(plot, colormap=[ 'viridis', 'plasma', 'inferno', 'magma', 'cividis'])
display(w)
Loading...