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

Z-zag time series plots #3212

Closed
4 tasks
elksie5000 opened this issue Oct 2, 2023 · 5 comments
Closed
4 tasks

Z-zag time series plots #3212

elksie5000 opened this issue Oct 2, 2023 · 5 comments
Labels

Comments

@elksie5000
Copy link

I'm not sure this is a bug report but I often seem to have what I call a zig-zag plot while trying plot time series

Probably best described with a question on Stackoverflow - the question

image

Please follow these steps to make it more efficient to solve your issue:

  • Since Altair is a Python wrapper around the Vega-Lite visualization grammar, most bugs should be reported directly to Vega-Lite. You can click the Action Button of your Altair chart and "Open in Vega Editor" to create a reproducible Vega-Lite example and see if you get the same error in the Vega Editor.
  • Search for duplicate issues.
  • Use the latest version of Altair.
  • Describe how to reproduce the bug and include the full code and data to reproduce it, ideally using a sample data set from vega_datasets.
@elksie5000 elksie5000 added the bug label Oct 2, 2023
@ChristopherDavisUCI
Copy link
Contributor

Thanks for the post. Can you please include a minimal example (including the portion defining the data)?

@elksie5000
Copy link
Author

elksie5000 commented Oct 2, 2023 via email

@ChristopherDavisUCI
Copy link
Contributor

Your Altair code looks fine to me, so my best guess is that it is an issue with the data. Maybe something with missing values? I tried using your sample data and was not able to reproduce the issue. (Is df a pandas DataFrame?)

linechart

@elksie5000
Copy link
Author

elksie5000 commented Oct 3, 2023 via email

@mattijn
Copy link
Contributor

mattijn commented Oct 3, 2023

I'm loving the homophone of Voltaire to Altair!
Your last comment is not entirely visible on Github, this is what we see: #3212 (comment).

Regarding your original question in SO:
To use a temporal datatype you will have to cast your integer year column to strings in your DataFrame before pushing it into the Altair chart.

df = pd.DataFrame(
    {
        "year": [2014, 2015, 2016, 2017, 2018, 2019],
        "admissions": [200, 300, 450, 500, 700, 900],
    }
)
df.year = df.year.astype(str)  # <---

alt.Chart(df).mark_line().encode(alt.X("year:T"), alt.Y("admissions:Q"))

image

See also

I think this issue is resolved. Closing this issue for now.
Feel free to open a new issue for feature requests or if you see behavior that is potentially a bug.

@mattijn mattijn closed this as completed Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants