from lets_plot import *
import numpy as np
LetsPlot.setup_html()
def f(x, y):
return x * y
x = np.arange(1, 11, 1)
y = np.arange(1, 11, 1)
X, Y = np.meshgrid(x, y)
df = dict(
x = X.reshape(-1),
y = Y.reshape(-1),
value = f(X, Y).reshape(-1)
)
p1 = ggplot(df, aes('x', 'y')) + geom_tile(aes(fill = 'value'))
# Basic form
p1 + scale_fill_continuous(guide = "colorbar")
p1 + scale_fill_continuous(guide = guide_colorbar())
p1 + guides(fill = guide_colorbar())
# Remove guide
p1 + scale_fill_continuous(guide = 'none')
p1 + guides(fill = 'none')
# Control styles
p1 + scale_fill_continuous(guide = guide_colorbar(barwidth = 10))
p1 + guides(fill = guide_colorbar(barwidth = 10))
p1 + scale_fill_continuous(limits = [0,20], breaks = [0, 5, 10, 15, 20], guide = guide_colorbar(nbin=5))
p2 = p1 + geom_point(aes(size = 'value'))
p2
p2 + guides(size = guide_legend(nrow=3), fill = guide_colorbar(nbin = 8))
# independent guides control
(
p2
+ scale_size(guide = guide_legend(nrow=3))
+ scale_fill_continuous(guide = guide_colorbar(nbin = 8))
)
(
p2
+ scale_size(guide = guide_legend(nrow=3))
+ guides(fill = guide_colorbar(nbin = 8))
)