Dynamic Text Just Above An Altair Chart
In the chart produced by the code below, the user can hover over the line segment to display a point on the chart, and information about the point is shown above the chart. import
Solution 1:
Altair scales have both a domain and a range. The domain refers to the extent of the data, and the range refers to the extent of the visual scale.
In the case of x
and y
encodings, the range is measured in pixels from the left of the chart (for x
) and from the top of the chart (for y
). Setting an encoding value
always refers to the range, not the domain.
So if you want the text to appear in a specific place regardless of the dataset, don't tie the text range position to values in the dataset. For example, you could do:
y=alt.value(-1)
and remove the dy
setting from your mark properties. This would specify that you want the text baseline to be 1 pixel above the top of the y axis.
Post a Comment for "Dynamic Text Just Above An Altair Chart"