#!/usr/bin/env python # coding: utf-8 # # Color Scales Using Matplotlib's Colormap # # Use `scale_color_cmapmpl()`, `scale_fill_cmapmpl()`, or `scale_cmapmpl()` to extract colors from a colormap and apply them to your chart. # # If a colormap is registered with Matplotlib, you can access it by its name. Otherwise, you can pass a cmap object directly. # # **Note:** These functions require Matplotlib to be installed in your environment. # In[1]: import numpy as np from lets_plot import * # In[2]: LetsPlot.setup_html() # In[3]: np.random.seed(42) n = 100 x = np.random.uniform(-1, 1, size=n) y = 25 * x ** 2 + np.random.normal(size=n) p = ggplot({'x': x, 'y': y}) \ + geom_point(aes(x='x', y='y', fill='y'), shape=21, size=7, color='white') # In[4]: p + scale_fill_cmapmpl('magma') # In[5]: p + scale_fill_cmapmpl('Dark2')