Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Simple Isotype grid example #1289

Merged
merged 5 commits into from
Jan 14, 2019
Merged

DOC: Simple Isotype grid example #1289

merged 5 commits into from
Jan 14, 2019

Conversation

palewire
Copy link
Contributor

@palewire palewire commented Jan 8, 2019

Mirrors a Vega-Lite example upstream.

visualization 2

import altair as alt
import pandas as pd

data = pd.DataFrame([dict(id=i) for i in range(1, 101)])

alt.Chart(data).transform_calculate(
    col="ceil (datum.id/10)"
).transform_calculate(
    row="datum.id - datum.col*10"
).mark_point(filled=True, size=50).encode(
    x=alt.X("col:O", axis=None),
    y=alt.Y("row:O", axis=None),
    shape=alt.ShapeValue("M1.7 -1.7h-0.8c0.3 -0.2 0.6 -0.5 0.6 -0.9c0 -0.6 -0.4 -1 -1 -1c-0.6 0 -1 0.4 -1 1c0 0.4 0.2 0.7 0.6 0.9h-0.8c-0.4 0 -0.7 0.3 -0.7 0.6v1.9c0 0.3 0.3 0.6 0.6 0.6h0.2c0 0 0 0.1 0 0.1v1.9c0 0.3 0.2 0.6 0.3 0.6h1.3c0.2 0 0.3 -0.3 0.3 -0.6v-1.8c0 0 0 -0.1 0 -0.1h0.2c0.3 0 0.6 -0.3 0.6 -0.6v-2c0.2 -0.3 -0.1 -0.6 -0.4 -0.6z")
).properties(width=400, height=400).configure_view(strokeWidth=0)

@palewire palewire changed the title Doc: Simple Isotype grid example DOC: Simple Isotype grid example Jan 8, 2019
@jakevdp
Copy link
Collaborator

jakevdp commented Jan 8, 2019

Looks good – I'd prefer to avoid the long line and define the shape outside the chart; e.g.

import altair as alt
import pandas as pd

data = pd.DataFrame([dict(id=i) for i in range(1, 101)])

person = ("M1.7 -1.7h-0.8c0.3 -0.2 0.6 -0.5 0.6 -0.9c0 -0.6 "
          "-0.4 -1 -1 -1c-0.6 0 -1 0.4 -1 1c0 0.4 0.2 0.7 0.6 "
          "0.9h-0.8c-0.4 0 -0.7 0.3 -0.7 0.6v1.9c0 0.3 0.3 0.6 "
          "0.6 0.6h0.2c0 0 0 0.1 0 0.1v1.9c0 0.3 0.2 0.6 0.3 "
          "0.6h1.3c0.2 0 0.3 -0.3 0.3 -0.6v-1.8c0 0 0 -0.1 0 "
          "-0.1h0.2c0.3 0 0.6 -0.3 0.6 -0.6v-2c0.2 -0.3 -0.1 "
          "-0.6 -0.4 -0.6z")

alt.Chart(data).transform_calculate(
    col="ceil (datum.id/10)"
).transform_calculate(
    row="datum.id - datum.col*10"
).mark_point(filled=True, size=50).encode(
    x=alt.X("col:O", axis=None),
    y=alt.Y("row:O", axis=None),
    shape=alt.ShapeValue(person)
).properties(width=400, height=400).configure_view(strokeWidth=0)

Random thought... we might even think about adding a library of common SVG shapes to Altair, so we could do e.g. alt.shapes.person, alt.shapes.cow, etc.

@palewire
Copy link
Contributor Author

palewire commented Jan 8, 2019

@jakevdp, I've made the changes you requested. I also flipped the order of how records are drawn to move left-to-right from the upper left, rather than top to bottom. I think this better represents how people read and will work look better in more complicated examples.

@palewire
Copy link
Contributor Author

palewire commented Jan 8, 2019

Also, I think that packaging isotypes sounds like a grand idea. Though I wonder if a good independent package of SVG isotypes already exists. And if it doesn't, somebody should make it.

@jakevdp
Copy link
Collaborator

jakevdp commented Jan 8, 2019

I don't know of any existing collection of SVG paths for use in isotype plots... but there may be one out there. Maybe @domoritz or @kanitw might know?

@kanitw
Copy link
Member

kanitw commented Jan 9, 2019

I'm not aware of any. But it sounds definitely useful. :)

@palewire
Copy link
Contributor Author

palewire commented Jan 9, 2019

Fun fact: This guy is sitting on my desk right now, challenging me.

img_20190108_172736

@jakevdp
Copy link
Collaborator

jakevdp commented Jan 14, 2019

I'm going to merge this - we can discuss creating isotype collections at a later point!

@jakevdp jakevdp merged commit 3d4c987 into vega:master Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants