lets-plot icon indicating copy to clipboard operation
lets-plot copied to clipboard

Geometries with fill have visible gaps

Open IKupriyanov-HORIS opened this issue 5 months ago • 0 comments

Some of the plots don't look very appealing:

import numpy as np
from lets_plot import *
LetsPlot.setup_html()

np.random.seed(43)
data = {
    'x': np.append(np.random.normal(0,1,1000), np.random.normal(3,1,500)),
    'y': np.append(np.random.normal(0,1,1000), np.random.normal(3,1,500))
}
ggplot(data, aes('x', 'y')) + geom_density2df(aes(fill = '..level..'))

image

import pandas as pd
from lets_plot import *
LetsPlot.setup_html()

df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")

n = 12
quantiles=[i/n for i in range(0, n)]

ggplot(df, aes('hwy', group='drv')) + \
    geom_density(aes(fill='..quantile..'), quantiles=quantiles, alpha=.97, show_legend=False) + \
    ggsize(800, 300)

image

import math 
from lets_plot import *
LetsPlot.setup_html()

X_max = 50
Y_max = 50
def z_fun(x, y):
    z = math.sin(x * 3 * math.pi / X_max)
    z += math.sin(y * 3 * math.pi / Y_max)
    z += x * 3 / X_max
    z += y * 5 / Y_max
    return z

x = []
y = []
z = []

for row in range(0, Y_max - 1):
    for col in range(0, X_max - 1):
        x.append(col)
        y.append(row)
        z.append(z_fun(col, row))

dat = dict(x=x, y=y, z=z)


ggplot(dat) + geom_contourf(aes('x', 'y', z='z', fill='..level..'), bins=20)

image

We can try to fix this by using an integer grid. If the coordinate is next to an occupied cell - use the coordinates of the cell, otherwise round the coordinate and take the place in the grid.

IKupriyanov-HORIS avatar Jan 10 '24 11:01 IKupriyanov-HORIS