Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Scatter with animation_frame is plotted out of order #23

Closed

Description

@dvduvix

I tried to plot a scatter with plotly express and I got a very weird behavior

Any thoughts?

Activity

  1. nicolaskruchten commented on Mar 22, 2019

    @nicolaskruchten
    Contributor

    If you're using Python 2, then order is not guaranteed unfortunately and you'll have to use the category_orders argument to specify the order for now.

  2. dvduvix commented on Mar 22, 2019

    @dvduvix
    Author

    @nicolaskruchten I am using Python 3. But for the sake of trying: how do I use category_orders?

  3. nicolaskruchten commented on Mar 22, 2019

    @nicolaskruchten
    Contributor

    If you're using Python 3 then this is a bug :) Can you post a minimal reproducible example in source here please?

    the category_orders argument is a dict where the keys are column names and the values are lists containing the values you want to see in the order you want to see them. So in this case you'd have category_orders={"frame": [0,1,2,3,...]}

  4. nicolaskruchten commented on Mar 22, 2019

    @nicolaskruchten
    Contributor

    Ah, sorry, I should be clearer: if you're using Python below 3.7 (i.e. not just 2.*) then order is not guaranteed. As of Python 3.7 iterating over dict keys is guaranteed to be in insertion order

  5. dvduvix commented on Mar 22, 2019

    @dvduvix
    Author

    @nicolaskruchten Then that must be it. I have Python 3.5.2

  6. kmader commented on Mar 22, 2019

    @kmader
    Contributor

    Thanks for that insight about Python 3.5.2 vs 3.7 I hadn't thought of that. Here is the minimal code/environment to run it https://gist.github.com/kmader/7a182744194a5330008b6e40d60aea6b and the link to just run it on mybinder: https://mybinder.org/v2/gist/kmader/7a182744194a5330008b6e40d60aea6b/master?filepath=example.ipynb

    As Kaggle Kernels use Python >3.5 it works fine on their site: https://www.kaggle.com/kmader/plotly-express-bug

  7. dvduvix commented on May 2, 2019

    @dvduvix
    Author

    @nicolaskruchten So I finally decided to test the theory and installed Python 3.7.3. The out of order problem remains.

    The only thing that worked to fix this was using the category_orders.

  8. nicolaskruchten commented on May 8, 2019

    @nicolaskruchten
    Contributor

    @dvduvix this is very puzzling... are you able to share a CSV of your data or some other way I could reproduce this locally?

  9. nicolaskruchten commented on May 8, 2019

    @nicolaskruchten
    Contributor

    (also, perhaps try with v0.1.8 which just came out with a subtle change that might just shake this problem loose)

  10. MengyinZhong commented on May 9, 2019

    @MengyinZhong

    @dvduvix
    Hi, I met the same issue and I attempted to fix it, but it doesn't seem to work, so could you please post your code? Thx a lot~😃

  11. dvduvix commented on May 9, 2019

    @dvduvix
    Author

    @MengyinZhong
    All I did is added a category_orders to scatter.

    px.scatter(data, animation_frame='frame', animation_group='col_name', category_orders={0: range(1000)})

    where 0 is the column name (use quotes if your column has an actual name) and range can be replaced with the list of all the items of that particular column but in the order you want.

    @nicolaskruchten I cannot share the file right now, but it's just a CSV file in the following format"
    index,value1x,value1y,value2x,value2y....

    I will try the latest version as soon as I can

  12. nicolaskruchten commented on May 9, 2019

    @nicolaskruchten
    Contributor

    I'm really struggling to replicate this bug on this end with Python 3.7. In fact, I'm struggling to get the frames to render out of order at all no matter what I do to the data frame :)

  13. MengyinZhong commented on May 10, 2019

    @MengyinZhong

    @dvduvix Thank you for your reply, and I tried the solution you provided, but the timeline is still out of order, shown as below
    scatter

  14. nicolaskruchten commented on May 10, 2019

    @nicolaskruchten
    Contributor

    @MengyinZhong what version of Python and plotly_express are you using?

  15. nicolaskruchten commented on May 13, 2019

    @nicolaskruchten
    Contributor

    OK, I've just pushed what I believe is a fix for this in version 0.2.1, such that animation frames by default now should always render in the order the values are encountered in the input data frame. Please let me know if you're still encountering issues with this latest version!

  16. MengyinZhong commented on May 13, 2019

    @MengyinZhong

    @nicolaskruchten
    Python 3.7.0
    plotly_express 0.2.1
    Sorry for my tardy reply, but the order still cannot show as expected:
    scatter

  17. nicolaskruchten commented on May 13, 2019

    @nicolaskruchten
    Contributor

    Wow, that's really bizarre. Can you share your data as well so that I can replicate this locally? What happens if you don't set category_orders at all with v0.2.1?

  18. MengyinZhong commented on May 13, 2019

    @MengyinZhong

    @nicolaskruchten I got the same result without setting category_orders. Here is my data https://github.com/MengyinZhong/test/blob/master/test.csv

  19. nicolaskruchten commented on May 13, 2019

    @nicolaskruchten
    Contributor

    OK, thanks for sharing this data! I can reproduce your problem on this end and I'll try to push out another fix shortly. I really appreciate the patience and follow-through: this makes the library better for everyone 😄 🙏

  20. nicolaskruchten commented on May 13, 2019

    @nicolaskruchten
    Contributor

    OK, I think I've got it for real this time! Please try v0.2.2, with or without category_orders, on any version of Python :)

  21. nicolaskruchten commented on Jun 3, 2019

    @nicolaskruchten
    Contributor

    Closing for now, please reopen if this happens again :)

  22. ariewjy commented on Jul 18, 2023

    @ariewjy

    Hi, @nicolaskruchten ,

    I have the same problem, the year animation frame is out of order, and I am having the same issue in my laptop and also in Kaggle notebook.
    CleanShot 2023-07-19 at 01 16 38

    Here is the link to the notebook to replicate the issue.
    https://www.kaggle.com/ariewijaya/plotly-animation-bug

    I am using latest plotly, same as in Kaggle Notebook.
    CleanShot 2023-07-19 at 01 17 00

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions