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

Attempt to format label for temporal data ends with same value #1608

Closed
chrislkeller opened this issue Jul 12, 2019 · 3 comments
Closed

Attempt to format label for temporal data ends with same value #1608

chrislkeller opened this issue Jul 12, 2019 · 3 comments

Comments

@chrislkeller
Copy link

chrislkeller commented Jul 12, 2019

This could be similar to parsing mentioned in @palewire's #1027, but i don't know.

My time data is unix timestamps, and I'm pretty certain the scale (space) between days is correct. But when I attempt to format, the values are repeated - in case Sunday or Jan. 18 1970 which is so close to the Unix Epoch that it makes me scratch my head.

Any ideas on what might be happening? Full notebook is here

visualization

# Convert to dataframe
data = pd.DataFrame(source)

# chart title
title = 'Ridgecrest aftershocks tapering off'

tick_range = list(range(1562137200, 1563001180, 86400))

# Configure the chart
frequency_chart = alt.Chart(
    source,
    title=title
).mark_circle().encode(
    size=alt.Size(
        'style_size:Q',
        legend=None
    ),
    opacity=alt.value(1),
    x=alt.X(
        'raw_time:T',
        title=config['alt_sources'],
        scale=alt.Scale(
            domain=[1562137200, 1563001180]
        ),
        axis=alt.Axis(
            ticks=True,
            tickCount=10,
            values=tick_range,
            domain=True,
            grid=False,
            labels=True,
            formatType='time',
            format=('%A'),
        ),
    ),
    y=alt.Y(
        'mag:Q',
        title=None,
        axis=alt.Axis(
            domain=False,
            ticks=True,
            grid=True,
        ),
    )
).properties(
    width=800,
    height=400
).configure_view(
    strokeWidth=0
)

frequency_chart
@jakevdp
Copy link
Collaborator

jakevdp commented Jul 12, 2019

It looks like your raw timestamps are in seconds since the Unix zero time, while Altair expects timestamps expressed in milliseconds since the Unix zero time. If you multiply all your raw times by 1000, I think the chart will be closer to what you expect.

@chrislkeller
Copy link
Author

@jakevdp - Changing things to milliseconds crashes the plot in Jupyter and I have to re-start.

Am going to close this and chalk it up to user error. Thank you for so much for the response.

@jakevdp
Copy link
Collaborator

jakevdp commented Jul 22, 2019

Changing things to milliseconds crashes the plot in Jupyter

Maybe you didn't change the step size in your tick range? If you're trying to draw 1000x the ticks you were originally, it can lead to issues with the javascript frontend when it tries to draw and label all of those ticks.

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

No branches or pull requests

2 participants