#!/usr/bin/env python # coding: utf-8 # # HCL color model. # # Lets-Plot now uses the `HCL` color model instead of `HLV`. This change affects hue scale and gradient scales (both color and greyscale). # # In[1]: from lets_plot import * # In[2]: LetsPlot.setup_html() # In[3]: data = { 'x': ['A', 'B', 'C', 'D', 'E', 'F'] } p = ggplot(data) \ + geom_boxplot(aes(x='x', fill='x'), stat='identity', lower=25, middle=50, upper=75, ymin=0, ymax=100) # Palette for discrete data: # In[4]: p + scale_fill_hue() # Hue gradient: # In[5]: data = { 'x': list(range(256)) } ggplot(data) \ + geom_tile(aes(x='x', fill='x', color='x'), size=1) \ + scale_fill_hue() \ + scale_color_hue() \ + coord_cartesian() \ + ggsize(800, 200) # Gradient: # In[6]: df = { 'x': list(range(256)) } ggplot(df) \ + geom_tile(aes(x='x', fill='x', color='x'), size=1) \ + scale_fill_gradient(low="#00FF00", high="#FF0000") \ + scale_color_gradient(low="#00FF00", high="#FF0000") \ + coord_cartesian() \ + ggsize(800, 200) # Gradientn # In[7]: df = { 'x': list(range(256)) } ggplot(df) \ + geom_tile(aes(x='x', fill='x', color='x'), size=1) \ + scale_fill_gradientn(colors=["#00FF00", "#FF0000", "#0000FF"]) \ + scale_color_gradientn(colors=["#00FF00", "#FF0000", "#0000FF"]) \ + coord_cartesian() \ + ggsize(800, 200) # Greyscale gradient: # In[8]: df = { 'x': list(range(256)) } ggplot(df) \ + geom_tile(aes(x='x', fill='x', color='x'), size=1) \ + scale_color_grey(start=0.1, end=0.9) \ + scale_fill_grey(start=0.1, end=0.9) \ + coord_cartesian() \ + ggsize(800, 200) # Viridis # In[9]: df = { 'x': list(range(256)) } ggplot(df) \ + geom_tile(aes(x='x', fill='x', color='x'), size=1) \ + scale_fill_viridis() \ + scale_color_viridis() \ + coord_cartesian() \ + ggsize(800, 200) # Parameter `h_start` now works with descrete data: # In[10]: p + scale_fill_hue(h_start=180) # Parameter `l` now correctly controls lightness: # In[11]: p + scale_fill_hue(c=95, l=75) + ggtitle('scale_fill_hue(c=95, l=75)') # # SANDBOX # In[12]: def dump_spec(plot, display=None): import json try: import clipboard except: clipboard = None from lets_plot._type_utils import standardize_dict plot_dict = standardize_dict(plot.as_dict()) plot_json = json.dumps(plot_dict, indent=2) if clipboard: clipboard.copy('') clipboard.copy(str(plot_json)) else: if display is None: display = True if display: print(plot_json) return plot # In[13]: data = { 'x': list(range(60)) } dump_spec(ggplot(data) \ + geom_tile(aes(x='x', fill='x', color='x'), size=1) \ + scale_fill_hue() \ + scale_color_hue() \ + coord_cartesian() \ + ggsize(600, 200)) # In[14]: dump_spec(ggplot(data) \ + geom_tile(aes(x='x', fill='x', color='x'), size=1) \ + scale_fill_grey() \ + scale_color_grey() \ + coord_cartesian() \ + ggsize(600, 200)) # In[15]: df = { 'x': list(range(59)) } dump_spec( ggplot(df) \ + geom_tile(aes(x='x', fill='x', color='x'), size=1, height=40) \ + scale_fill_gradient(low="#00FF00", high="#FF0000") \ + scale_color_gradient(low="#00FF00", high="#FF0000") ) # In[16]: ggplot(df) + geom_tile(aes(x='x', fill='x'), height=40) + scale_fill_gradient(low = "yellow", high = "red") # In[17]: dump_spec(p + scale_fill_hue(h = [15, 375], c = 100, l = 100)) # In[18]: df = { 'x': list(range(256)) } ggplot(df) \ + geom_tile(aes(x='x', fill='x', color='x'), size=1) \ + scale_fill_viridis() \ + scale_color_viridis() \ + coord_cartesian() \ + ggsize(800, 400) # In[19]: ggplot(df) \ + geom_tile(aes(x='x', fill='x', color='x'), size=1) \ + scale_fill_viridis() \ + scale_color_viridis(option='A') \ + coord_cartesian() \ + ggsize(800, 400) # In[ ]: