I'm generating a plot with the following code (in an ipython notebook):
import altair as alt
import pandas as pd
events = pd.DataFrame(
[
{"event": "Task A", "equipment": "SK-101", "start": 10.2, "finish": 11.3},
{"event": "Task B", "equipment": "SK-102", "start": 6.5, "finish": 10.2},
{"event": "Task C", "equipment": "SK-103", "start": 3.3, "finish": 11.3},
{"event": "Task D", "equipment": "SK-104", "start": 4.7, "finish": 5.5},
{"event": "Task E", "equipment": "SK-105", "start": 13.0, "finish": 13.2},
{"event": "Task F", "equipment": "SK-106", "start": 1.1, "finish": 7.9},
{"event": "Task G", "equipment": "SK-107", "start": 7.4, "finish": 10.0},
{"event": "Task H", "equipment": "SK-108", "start": 6.6, "finish": 7.6},
{"event": "Task I", "equipment": "SK-109", "start": 8.5, "finish": 16.7},
{"event": "Task J", "equipment": "SK-110", "start": 9.0, "finish": 12.2},
{"event": "Task K", "equipment": "SK-111", "start": 10.2, "finish": 17.3},
{"event": "Task L", "equipment": "SK-112", "start": 6.1, "finish": 9.5},
{"event": "Task M", "equipment": "SK-113", "start": 5.4, "finish": 5.8},
{"event": "Task N", "equipment": "SK-114", "start": 2.2, "finish": 8.3},
{"event": "Task O", "equipment": "SK-115", "start": 9.3, "finish": 10.6},
{"event": "Task P", "equipment": "SK-116", "start": 3.9, "finish": 12.5},
{"event": "Task Q", "equipment": "SK-117", "start": 11.1, "finish": 16.6},
{"event": "Task R", "equipment": "SK-118", "start": 14.4, "finish": 18.4},
{"event": "Task S", "equipment": "SK-119", "start": 19.2, "finish": 19.9},
{"event": "Task T", "equipment": "SK-120", "start": 13.8, "finish": 16.7},
{"event": "Task U", "equipment": "SK-102", "start": 12.0, "finish": 13.0},
{"event": "Task V", "equipment": "SK-106", "start": 10.2, "finish": 17.3},
{"event": "Task W", "equipment": "SK-108", "start": 12.8, "finish": 14.9},
{"event": "Task X", "equipment": "SK-110", "start": 12.6, "finish": 18.9},
{"event": "Task Y", "equipment": "SK-112", "start": 13.3, "finish": 18.3},
{"event": "Task Z", "equipment": "SK-114", "start": 8.6, "finish": 19.2},
]
)
brush = alt.selection_interval(encodings=["y"])
minimap = (
alt.Chart(events)
.mark_bar()
.add_params(brush)
.encode(
x=alt.X("start:Q", title="", axis=alt.Axis(labels=False, tickSize=0)),
x2="finish",
y=alt.Y("equipment:N", title="", axis=alt.Axis(labels=False, tickSize=0)),
color=alt.condition(brush, "event", alt.value("lightgray")),
)
.properties(
width=100,
height=400,
title="minimap"
)
)
detail = (
alt.Chart(events)
.mark_bar()
.encode(
x=alt.X("start:Q", title="time (hr)"),
x2="finish",
y=alt.Y("equipment:N").scale(domain={"param": brush.name, "encoding": "y"}),
color="event",
)
.properties(width=600, height=400, title="Equipment Schedule")
)
detail | minimap
The idea is that the minimap plot on the right is used to zoom/pan the y-axis of the main plot. When I zoom or pan with the mouse in the minimap, I see strange artifacts at the top of the main plot; it looks like all bars above the selected area get rendered at the top of the plot.
Is this something I'm doing wrong, or is it some sort of rendering bug?
I'm unsure why that happens, but another approach would be to use the brush as a filter instead of to set the y-domain. As long as you are able to set a fixed x-domain I think this can work well for what you need:
detail = (
alt.Chart(events)
.mark_bar()
.encode(
x=alt.X("start:Q", title="time (hr)").scale(domain=(0, 20)),
x2="finish",
y=alt.Y("equipment:N"),
color="event",
)
.properties(width=600, height=alt.Step(20), title="Equipment Schedule")
).transform_filter(brush)
I also set the height to a step size here, which gives you more of the scrolling behavior you mentioned in your other issue.