Sunburst Treemap Tutorial - Plotly

Поделиться
HTML-код
  • Опубликовано: 17 сен 2024

Комментарии • 57

  • @rafaelcapellopastore254
    @rafaelcapellopastore254 2 года назад +1

    Wow, it was amazing... was trying to make a treemap at work and spent an entire afternoon at Google - then I found out this video and boom, in less than 30 minutes it was great.
    I am looking forward for your book!!! Keep up with the good work

  • @aminghanooni4240
    @aminghanooni4240 3 года назад +1

    Your tutorials on Plotly are just awesome! Thanks for sharing! 👌🎉

    • @CharmingData
      @CharmingData  3 года назад +1

      You're welcome, @Amin. Let me know of you have questions with anything

  • @nikhilshingadiya7798
    @nikhilshingadiya7798 3 года назад +1

    your hard work is boon for us

  • @stoufa
    @stoufa 3 года назад +1

    Bro, We can't thank you enough for such great content; Keep up the awesome work 😊

  • @akhrorjonpulatov8590
    @akhrorjonpulatov8590 Год назад

    Bro, I really appreciate your hardwork, and your helpful contents. Your tutorials are just perfect and in detail. I have learnt a lot from your tutorials, and I genuinely love all of the contents. Thanks bro

  • @Smoked93POL
    @Smoked93POL 3 года назад

    Great Tutorial! For me it was 98% of time spend on cleaning the data from my own Excel file and 2% of fun with modyfing the sunburst. It is very cool and useful tutorial!

  • @papayatmadiop2425
    @papayatmadiop2425 3 года назад +1

    Excellent tutorial, thank u so much !

  • @GiuseppeSerraonline
    @GiuseppeSerraonline 4 года назад

    excellent video tutorial, I'll be glad to share it around, is very well done, congrats again

  • @J_Arthur_
    @J_Arthur_ 3 года назад

    Quality content ! Thank you kindly < 3

  • @MusicNewb
    @MusicNewb 3 года назад

    OMG THIS IS BRILLIANT!!! THANK YOU SO MUCH!
    I have an additional question: is it possible to also add/display the percent entry into the hoverdata?

  • @wiki-infodevelopment3369
    @wiki-infodevelopment3369 2 года назад

    Great! :)

  • @benarnold5738
    @benarnold5738 2 года назад +1

    Great tutorial! It's been so helpful for me at work to visualise a complicated spreadsheet.
    One point that I have noticed with my own sunburst, and with some of yours, often the total percentage doesn't add to 100%, going instead to either 99% or 101%. I assume this is a rounding error but do you know a quick fix for this to guarantee 100% every time?
    Thanks again for your great tutorial.

    • @CharmingData
      @CharmingData  2 года назад

      Thanks for watching, Ben. I agree. It's probably a rounding error, but I'm not sure how to fix that.

  • @joewilliams5028
    @joewilliams5028 2 года назад

    Love the channel, been a lifesaver more than once.
    I do have a quick q though, when I try and load the sunburst graph using dash it just loads a whitescreen (with the title and colorbar), even though the same plot works perfectly in Jupyter Notebooks. Weirdly enough it will work in Dash if I change the branchvalues parameter to 'remainder' instead of 'total', but I need to keep it as total. You have any idea how this would happen?
    Thanks again for the tutoirals.

    • @CharmingData
      @CharmingData  2 года назад

      hi @Joe, Thanks for the compliments. I'm not sure what's going on. Maybe it's a version control problem. What version of Dash are you using when working with Jupyter, and what version of Dash do you use when working with a Python IDE?

  • @adityajawla723
    @adityajawla723 4 года назад +1

    Hi Adam , thanks for such nice detailed tutorial. I am following each tutorial and learning fast . But is it possible to you to have a video on “chained callbacks” and “theme” in dash. Thanks in advance 🙏

    • @CharmingData
      @CharmingData  4 года назад

      Hi Aditya, when you say "chained callbacks", are you referring to Pattern-Matching Callbacks and basic callbacks?
      dash.plotly.com/basic-callbacks

    • @adityajawla723
      @adityajawla723 4 года назад

      Charming Data Hi Adam, exactly what i mean. I am trying to create callbacks in which pattern can be used to create dynamic UIs where one input component updates the available options of the next input component.

    • @CharmingData
      @CharmingData  4 года назад +1

      @@adityajawla723 ok. That's better to do with pattern matching callbacks. I hope to post a tutorial about this next week. In the meantime, this is a good read that might help you: dash.plotly.com/pattern-matching-callbacks

  • @t_tek760
    @t_tek760 4 года назад

    Awesome!!!

  • @CK-qh5te
    @CK-qh5te 3 года назад

    @Charming Data Hi I have another question :) In the challenge problem, how does plotly determine the color of the inner wedges that aren't male/female?

    • @CK-qh5te
      @CK-qh5te 3 года назад

      Figured this out in documentation for anyone who is interested "the first color of the discrete color sequence is used"

    • @CharmingData
      @CharmingData  3 года назад

      @@CK-qh5te thanks for sharing, Chris

  • @anupjoseph7368
    @anupjoseph7368 3 года назад +1

    Hi Adam, thanks for the tutorial. Your series on Plotly is by far the best I could find for free or paid.
    There something interesting I found here though. I was running this code through on Google colab and colab promptly errored out saying "TypeError: sunburst() got an unexpected keyword argument 'path'". This is weird as its literally used again and again in the documentation. When I tried to run other code snippets in the documentation on colab it gave the exact same error with sunburst chart. All this code works perfectly fine on my local machine though.
    If the chart type is unsupported on colab shouldn't it say that instead of giving these kind of error messages? Any idea why this is happening

    • @CharmingData
      @CharmingData  3 года назад

      That's very interesting, @Anup. Maybe you found some kind of incompatibility between Plotly and Google colab. Maybe using the parameter "path" is not compatible with the way Google writes its code.
      It's so wierd. Thanks for sharing.

  • @rohanplaylist3843
    @rohanplaylist3843 3 года назад

    Thanks a lot, Adam! However, I am still having difficulties with:
    1. hover_data - whenever I try to select a specific label to change it to false I am getting "keyword argument repeated"?
    2. giving a specific color to root - when the "Color" field is set to one of the branches and not the root.
    3. Do you believe there's a way i could have multiple sunburst charts plot in one row as appose to them being showing in different rows?

    • @CharmingData
      @CharmingData  3 года назад

      Hi @Chavya. It's hard to say without seeing the code. Feel free to send me your code, error message, and line of code where the error appears to info@charmingdata.org

    • @rohanplaylist3843
      @rohanplaylist3843 3 года назад

      @@CharmingData Thanks, Adam! done, sent an email - I've also included the recent question I asked about displaying multiple sunburst charts in the same row, hope you could guide me on that one too.
      Thanks a lot for taking your time :)

    • @CharmingData
      @CharmingData  3 года назад +1

      @@rohanplaylist3843 got it. I'll take a look tomorrow or Monday. A big busy recording the next tutorial.

    • @rohanplaylist3843
      @rohanplaylist3843 3 года назад

      @@CharmingData Thank you Adam! i really appreciate you taking time to assist.

  • @emionok
    @emionok 3 года назад

    Hi, could you please explain how to deal with labels parameter? I have a boolean column and want to show other strings instead of True or False. Thanks a lot

    • @CharmingData
      @CharmingData  3 года назад

      Hi @emionok,
      If I understand your question correctly, you can do labels={"True": "red", "False": "blue"}. The labels parameter is used to changed the labels on the graph, specifically those labels that are being plotted like x axis and y axis. They usually refer to column names and not data in each row.
      If you need to change the row data from True/False to string , then just convert the data with pandas. Create a new column that will assign 'blue' to row 1 if row 1 of Boolean column is False, and the same with the True data.

    • @emionok
      @emionok 3 года назад

      @@CharmingData Thank you for your prompt reply. Do you know is there a possibility to change labels on sunburst? this way - labels={"True": "red", "False": "blue"} doesn't work. Thank you in advance

    • @CharmingData
      @CharmingData  3 года назад +1

      @@emionok probably not because the labels parameter would change the x or y labels, not the data points inside the axis. That's why you should create another column that has the new strings you are looking for. And plot that column.
      That didn't work for you?

    • @emionok
      @emionok 3 года назад

      @@CharmingData Thank, that definitely works, I just don't understand how the label parameter works in px.sunburst :)

    • @CharmingData
      @CharmingData  3 года назад

      @@emionok I'm glad you got it, @emionok. Hope you create many powerful dashboards 💪 . If you need help in the future, let me know. And if you'd like to support my channel, I would be grateful to you🙏
      ruclips.net/channel/UCqBFsuAz41sqWcFjZkqmJqQjoin

  • @r_pydatascience
    @r_pydatascience 2 года назад

    Is it possible to reorder the variables in the sectors of the sunburst plot?

    • @CharmingData
      @CharmingData  2 года назад +1

      Hi @R_py, I don't think so but I'll try to search more. What part of the sunburst would you like to reorder?

    • @r_pydatascience
      @r_pydatascience 2 года назад

      @@CharmingData it seems they don't allow adding stackoverflow links here. I asked the Q there but I have't received any response so far. In the tree map, or icicle map, I want to order one of the child variables.

    • @r_pydatascience
      @r_pydatascience 2 года назад

      @@CharmingData I would like to reorder the days of the week to appear in order: Thursday, Friday, and Sunday. How do you change that in plotly treemap? I appreciate your kind help.
      import plotly.express as px
      df = px.data.tips()
      fig = px.treemap(df, path=[px.Constant("all"), 'sex', 'day', 'time'],
      values='total_bill', color='time')
      fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
      fig.show()

    • @CharmingData
      @CharmingData  2 года назад

      @@r_pydatascience HI, I think for the sunburst, you can use fig.update_traces(sort=False), and then you can order the data at your end, in the direction desired. Or you can probably build the sunburst with Plotly GO. That could give you more control over the order of the root

    • @r_pydatascience
      @r_pydatascience 2 года назад

      @@CharmingData Thanks again, bro! I
      also thought adding fig.update_traces(sort=False) would do the job but it didn't order it with the natural order of the weeks(Thursday, Friday, Saturday, Sunday). I think that is probably done with a dictionary but I didn't manage to make it work.

  • @CK-qh5te
    @CK-qh5te 3 года назад

    For some reason the legend doesn't show up for me when I do the color scale sunburst chart. Is there a way to turn this on?

    • @CK-qh5te
      @CK-qh5te 3 года назад

      I tried "fig.update_layout(showlegend=True)" also but this didn't work either

    • @CharmingData
      @CharmingData  3 года назад

      @@CK-qh5te are you using the same code in using?

    • @CK-qh5te
      @CK-qh5te 3 года назад

      @@CharmingData Yup I ran your code copying from github.
      Also, the challenge file doesn't work for me. It says it expects "id" and "label" as a column in the dataframe. If I run the code with only {"Victim's Gender":"False"} it works. Not sure if this is a problem in my PyCharm or something. What do you think?
      Thanks for your help, really appreciate you making this tutorial and answering questions :)

    • @CharmingData
      @CharmingData  3 года назад

      ​@@CK-qh5te Hi Chris, I'm not sure what's wrong. Perhaps it's the plotly of Dash version you're using, because I just ran the challenge_solution file on my computer and it worked.

    • @CK-qh5te
      @CK-qh5te 3 года назад

      @@CharmingData Hm strange, I'll post on the plotly forum. I have plotly 4.14.3 and plotly express 0.4.1. Thanks!

  • @robdawg417
    @robdawg417 4 года назад +1

    Hey, can you do a video on an actual treemap

    • @CharmingData
      @CharmingData  4 года назад +1

      How Robert. Thanks for watching. I'll take a look and see. Was this sunburst tutorial helpful for you?

  • @CharmingData
    @CharmingData  4 года назад +1

    Hey Everyone. Here's the Challenge Solution. Let me know if you have any questions. Good luck: github.com/Coding-with-Adam/Dash-by-Plotly/blob/master/Plotly_Graphs/Sunburst/solution_challenge.py