JetBrains / lets-plot

Multiplatform plotting library based on the Grammar of Graphics
https://lets-plot.org
MIT License
1.57k stars 51 forks source link

Vertex sampling uses different tolerances for objects within the same plot #1174

Closed IKupriyanov-HORIS closed 2 months ago

IKupriyanov-HORIS commented 2 months ago

Sampling uses different tolerances for objects within the same plot:

from lets_plot import *
LetsPlot.setup_html()

from math import sin, cos
def circle(x, y, r, n, g, out):
    xs = []
    ys = []
    gs = [g] * n
    angle_step = 3.14 * 2 / n 
    angle = 0
    for i in range(n - 1):
        xs.append(x + cos(angle) * r)
        ys.append(y + sin(angle) * r)
        angle += angle_step

    xs.append(xs[0])
    ys.append(ys[0])

    out['x'].extend(xs)
    out['y'].extend(ys)
    out['g'].extend(gs)
    return out

data = { 'x': [], 'y': [], 'g': [] }
circle(10, 10, 5, 100, 'a', data)
circle (50, 50, 10, 100, 'b', data)
circle (70, 30, 15, 100, 'c', data)
circle (30, 70, 10, 100, 'd', data)
circle (30, 90, 5, 100, 'e', data)

p = ggplot(data, aes(x='x', y='y', group='g')) + coord_fixed()
p + geom_path(sampling=sampling_vertex_dp(100))

ggplot(data, aes(x='x', y='y')) + coord_fixed() + geom_polygon(sampling=sampling_vertex_dp(100))

Output: image

IKupriyanov-HORIS commented 2 months ago

Fixed via https://github.com/JetBrains/lets-plot/commit/80fcbf2b71b68311d89d5034c36849babb0c6086 image