[Question] Draw scatterplot of wedges with encoded size and angle
See original GitHub issueI want to implement Zan Armstrong’s comet chart in Altair, for which I need to draw a scatterplot of wedges with encoded start-point and end-points. I used glyphs in an earlier implementation in Bokeh.
I have read about wedge
as one of the available marks, and managed to draw wedges, all with the same configuration e.g. just changing the angle.
import altair as alt
import numpy as np
import pandas as pd
df = pd.DataFrame(
np.hstack((np.random.randn(100, 2), np.random.randint(0, 360, (100, 1)))),
columns=["x", "y", "angle"],
)
(alt.Chart(df).mark_point(shape='wedge', angle=135).encode(x="x:Q", y="y:Q"))
I was wondering whether it is possible to encode the wedges individually, where the length and direction are determined by the start and endpoint in the dataset. As a first test, I tried to encode angle='angle:Q
in the example above, but that property isn’t defined.
Vega-lite shape mark looks like another possible solution (see this SO post) and I see it is accessible in Altair as shown here) but I don’t know how to connect the dots.
If someone could point me in the right direction, I am happy to try and contribute a comet chart viz to Altair.
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (11 by maintainers)
Top GitHub Comments
@mattijn Thanks for the suggestions. I have just finished up writing a short blog post.
Happy to contribute. Your plot with the barley yield data, however, is not quite what is meant with a comet chart (although it does borrow elements from it). So just to check, I can submit a PR with the barley yield example, and we’ll just leave the rest of my work in the blogpost if that’s what you mean.
It is up to @jakevdp to decide what goes in and where. This thread might be difficult to follow since it started as a question.
I would close this issue and create a new separate issue offering to create a PR to include your example. Jake will most likely chime in with what is needed.