juba / pyobsplot

Observable Plot in Jupyter notebooks and Quarto documents
https://juba.github.io/pyobsplot/
MIT License
184 stars 8 forks source link

Problems with faceting #3

Closed juba closed 1 year ago

juba commented 1 year ago

Same data sources are seen as distinct, generating warning and disabling faceting by default.

Example:

import polars as pl
from pyobsplot import Obsplot, Plot

penguins = pl.read_csv("data/penguins.csv")

Obsplot({
    "facet": {"data": penguins, "x": "island"},
    "marks": [
        Plot.dot(penguins, {"x": "flipper_length_mm", "y": "body_mass_g", "fill": "species"}),
    ]
})
juba commented 1 year ago

Faceting now works correctly, but still generates a warning sign when used at top level. Mark level faceting is fine.

Fil commented 1 year ago

On the JS side, we test strict equality (===) between the facet data and the mark's data; in other words they must be the same reference, not only the same contents. (Not sure this comment helps much…)

juba commented 1 year ago

I managed to solve issue for the "main" mark, but I still get warnings for axis and ticks. For example, with the following code:

import polars as pl
from pyobsplot import Obsplot, Plot

pl.read_csv("https://github.com/juba/pyobsplot/raw/main/doc/data/penguins.csv")

op = Obsplot()

op({
    "grid": True,
    "facet": {"data": penguins, "x": "sex"},
    "marks": [
        Plot.dot(penguins, {"x": "culmen_depth_mm", "y": "body_mass_g"}),
        Plot.frame()
    ]
})

In the JavaScript console I don't get warnings for the dot mark, but I get them for frame, fx-axis tick labels, y-grid, y-axis tick, etc. Not sure how to avoid this (if this is possible). If I replace top level faceting by mark-level faceting the warnings disappear.

Fil commented 1 year ago

Is there a debug mode, a way to see what exactly is sent to Plot?

juba commented 1 year ago

Debug mode is now available with the widget renderer by adding debug=True when creating the plot generator object. It outputs the plot JavaScript structure in the browser console:

op = Obsplot(debug=True)
juba commented 1 year ago

Regarding this issue, it is reproducible in Plot outside of pyobsplot.

See https://github.com/observablehq/plot/issues/1429

juba commented 1 year ago

Should be fixed in Observable Plot 0.6.6.