System Colors¶
In [1]:
import pandas as pd
from lets_plot import *
from common import docs_dark_theme
In [2]:
LetsPlot.setup_html()
In [3]:
def get_system_color_plot(*, kind: str):
w, h = 400, 300
th, lh = 50, 75
width = w
height = h + th + lh
df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")
title_color = 'pen' if kind == 'paper' else 'paper'
title_label_size = None if kind == 'paper' else 0
p_title = ggplot() + \
geom_label(x=0, label=kind, \
size=10, label_size=title_label_size, color=title_color, fill=kind, family='mono') + \
theme_void()
if kind == 'pen':
label = 'A hight-contrast color\ncommonly used to draw dots and lines'
p_example = ggplot(df, aes("cty", "hwy")) + geom_point()
elif kind == 'brush':
label = 'A color we often use to fill shapes'
p_example = ggplot(df, aes("fl")) + geom_bar()
elif kind == 'paper':
label = 'A "background" color\nwe often use to fill shapes as well'
p_example = ggplot(df, aes("drv", "cty")) + geom_boxplot()
p_label = ggplot() + \
geom_text(x=0, label=label, size=10) + \
theme_void()
return ggbunch(
[p_title, p_label, p_example],
[(0, 0, w / width, th / height),
(0, th / height, w / width, lh / height),
(0, (th + lh) / height, w / width, h / height)]
) + ggsize(width, height)
In [4]:
pen_plot = get_system_color_plot(kind='pen')
ggsave(pen_plot, "aesthetics_color_pen.png")
brush_plot = get_system_color_plot(kind='brush')
ggsave(brush_plot, "aesthetics_color_brush.png")
paper_plot = get_system_color_plot(kind='paper')
ggsave(paper_plot, "aesthetics_color_paper.png")
gggrid([pen_plot, brush_plot, paper_plot]) + ggsize(1200, 500)
Out[4]:
In [5]:
pen_plot_dark = get_system_color_plot(kind='pen') + docs_dark_theme()
ggsave(pen_plot_dark, "aesthetics_color_pen_dark.png")
brush_plot_dark = get_system_color_plot(kind='brush') + docs_dark_theme()
ggsave(brush_plot_dark, "aesthetics_color_brush_dark.png")
paper_plot_dark = get_system_color_plot(kind='paper') + docs_dark_theme()
ggsave(paper_plot_dark, "aesthetics_color_paper_dark.png")
gggrid([pen_plot_dark, brush_plot_dark, paper_plot_dark]) + ggsize(1200, 500)
Out[5]: