Skip to content

Instantly share code, notes, and snippets.

@Ken-Kuroki
Created April 5, 2019 02:11
Show Gist options
  • Save Ken-Kuroki/d8ed7f76988cae7610926d22936d5356 to your computer and use it in GitHub Desktop.
Save Ken-Kuroki/d8ed7f76988cae7610926d22936d5356 to your computer and use it in GitHub Desktop.
Generic scatterplot function for Altair
def plot(df, x, y, args, fill=False):
df = df.reset_index()
index = df.columns[0]
if fill:
chart = alt.Chart(df).mark_circle(size=30)
else:
chart = alt.Chart(df).mark_point(size=30)
chart = chart.encode(
x=alt.X(x),
y=alt.Y(y),
tooltip=[index, x, y, *args.values()],
**args
).interactive()
return chart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment