Bar Graph -- Python Plotly

Поділитися
Вставка
  • Опубліковано 3 кві 2020
  • The Bar Graph: using Plotly Express & Python, this tutorial will teach you everything about the Bar Graph. How to build it, shape it, style it, and create an animated bar chart. We will be using real-life data on prisoners in India. Links below:
    View my book - The Book of Dash:
    www.amazon.com/Python-Dash-An...
    github.com/DashBookProject/Pl...
    The Code:
    github.com/Coding-with-Adam/D...
    The Data:
    drive.google.com/file/d/1Solf...
    Bar Graph with Plotly Express:
    plotly.com/python-api-referen...
    Plotly Continuous Color Scale:
    plotly.com/python/builtin-col...
    Plotly Animations:
    plotly.com/python/animations/
    Graphs Update_Layout:
    plotly.com/python-api-referen...
    Graphs Update_Traces:
    plotly.com/python-api-referen...

КОМЕНТАРІ • 113

  • @dianaamiri9520
    @dianaamiri9520 3 роки тому +16

    never have I ever experienced this much structured tutorial in youtube, glad that I found you. thanks

  • @lucass8031
    @lucass8031 3 роки тому +3

    Thank you so much for these tutorials!

  • @yunpeng_ma
    @yunpeng_ma 3 роки тому +4

    Amazing tutorial, the procedure is super helpful, thank you!

  • @gemedest3035
    @gemedest3035 3 роки тому +4

    Great Tutorial Adam! And great idea showing how to code with documentation. Thanks!

    • @CharmingData
      @CharmingData  3 роки тому +2

      Thank you Gemedes. I appreciate it. Are you using Dash for anything specific?

  • @MrCaraciolo
    @MrCaraciolo 2 роки тому +1

    AMAZING STUF!!! Keep on the great work!!!!!

  • @tattoo3dsimulation625
    @tattoo3dsimulation625 4 роки тому +1

    Very great content. I learned a lot from this super handy tutorial. Thanks for this.

  • @officesayan
    @officesayan 3 роки тому

    extremely happy to get so much clarity about plotly... Thanks alot

    • @CharmingData
      @CharmingData  3 роки тому

      You're welcome, @Sayan. Good luck with your plotting. Let me know if you need clarity on something

  • @DK-rl1sf
    @DK-rl1sf 2 роки тому

    Thanks for such an amazingly detailed explanation on Plotly. I love how you show instead of tell. By showing, you immediately get the point across. I've read documentations after documentations telling me what something is supposed to do yet couldn't figure out what is being said.

    • @CharmingData
      @CharmingData  2 роки тому

      Thank you DK. Do you also use the Plotly Forum for your questions?

    • @DK-rl1sf
      @DK-rl1sf 2 роки тому

      @@CharmingData No. Too new to Plotly to even know what to ask. Not a developer either. Just need to use python and some seaborn visualisations sporadically for work. So I really appreciate tutorials like this that shows whats out there and help build a strong foundation.

  • @abdullahansari5084
    @abdullahansari5084 3 роки тому

    Thanks a lot. prior to landing on this video, I spent an hour looking to place text inside a bar graph.

  • @romanbulatnikov7157
    @romanbulatnikov7157 4 роки тому +1

    Awesome tutorial in details!! Thanks!

    • @CharmingData
      @CharmingData  4 роки тому

      Thanks for watching, Roman. I'm glad you enjoyed.

  • @consultoriaecoingenieros6046
    @consultoriaecoingenieros6046 3 роки тому

    Love your tutorials

  • @Fasodre
    @Fasodre 3 роки тому +1

    I thank you sincerely for these tutorials... this is one of the best ones I've ever seen before! Amazing...

    • @CharmingData
      @CharmingData  3 роки тому +1

      You're welcome Fernando. Are you using dash Plotly for work?

    • @Fasodre
      @Fasodre 3 роки тому

      ​@@CharmingData Not yet. I would say I'm new to Python. I mainly use Power BI for dashboards, and I'm experiencing create plots in Matplot and Seaborn and moving for PBI... I'm looking to Plotly to see possibilities to use the graphs inside PBI too. But I'm really excited knowing the possibilities we have with Dash through your tutorials... Greetings from São Paulo-Brazil.

    • @CharmingData
      @CharmingData  3 роки тому +1

      @@Fasodre that's really exciting Fernando. I'm sure you will love Dash and Plotly. They are great libraries with powerful features.
      If you need any help along the way, Fernando, let me know.

  • @sau953
    @sau953 2 роки тому +1

    You sir are a Legend!

  • @nhubanhat
    @nhubanhat 3 роки тому

    I have never watched this tutorial as great as you have done like that. Thanks so much for contribution for python community. I'm going to follow all your videos and share your idea widely.

    • @CharmingData
      @CharmingData  3 роки тому +1

      Thank you @Nhu. Have you created any dashboard apps yet? How would you like to use Dash?

    • @nhubanhat
      @nhubanhat 3 роки тому

      @@CharmingData I've generated dashboards by some BI tools, but never tried created one by plotlly. I have plan to deploy and test some in small size using dash. Could you possibly share ideas about delivering dashboard by LAN (intranet permission), not by extranet like heroku or Python anywhere.
      Please help me out.

    • @CharmingData
      @CharmingData  3 роки тому

      @@nhubanhat I actually never delivered dashboard apps by LAN. Good luck, @Nhu.

  • @ankurkumar9660
    @ankurkumar9660 11 місяців тому +1

    wow it's Amazing 😍😍😍😍

  • @davedave2783
    @davedave2783 4 роки тому +2

    Hi Man,
    Awesome videos.
    Subscribed.

  • @SaintNath
    @SaintNath 3 роки тому

    Thanks, using this for my PhD project right now!

    • @CharmingData
      @CharmingData  3 роки тому

      Good luck @nath. If you'd like to support the education I provide or my channel in general, I'd really appreciate it.
      patreon.com/charmingdata

  • @johannesallgaier5722
    @johannesallgaier5722 3 роки тому +1

    Great video. Good continent.

  • @rdurango92
    @rdurango92 4 роки тому +1

    Hi . Thank you so much.... Excelent tutorial !!!!

    • @CharmingData
      @CharmingData  4 роки тому +1

      I'm glad you liked it, Ruben. I am trying to gather more supporters to create higher quality educational tutorials on Dash. My goal is to reach 15 supporters, and it would be great if you were one of my first 15 👍 www.patreon.com/charmingdata
      I hope you create beautiful Dashboards, let me know if you have any questions in the future.

  • @zulfiqarahmedcanadian
    @zulfiqarahmedcanadian 3 роки тому

    You are really grate sir

    • @CharmingData
      @CharmingData  3 роки тому

      Thank you, @Zulfaqar. Have you built any dash apps yet?

  • @skyful9
    @skyful9 2 роки тому

    We can plot pivot table and groupby data with matplotlib very easily, but in Plotly every analysis you do must be transformed into Dataframe in order to visualize it with plotly !!

  • @professionalcricketinsights
    @professionalcricketinsights 2 роки тому +2

    Hello, Brilliant!.
    Could you please advise in which order I must learn all playlists to start from beginning and move step by step into advanced level?
    Please recommend. Thank you immensely.

  • @ahmedtejanfoday3138
    @ahmedtejanfoday3138 2 роки тому +2

    thanks for very much!!! it was helpful. Can you please use % on those bars without creating another column?

  • @exlonkgil6465
    @exlonkgil6465 Рік тому

    I love you, a lot.

  • @Aravinda_Raj
    @Aravinda_Raj 2 роки тому

    Is that possible to add the value of relative barmode count both and display on the top of the chart?

  • @arthurh1969
    @arthurh1969 2 роки тому

    Amazing explanation! Is it possible to right click a bar and download that piece of data as a CSV?

  • @siddarthg3214
    @siddarthg3214 2 роки тому

    Hey, Can you tell me how to limit the number of the bar chart? suppose I have 40 values and I want to present only the top 10 values in descending order.

  • @rodrigoolmedo160
    @rodrigoolmedo160 3 роки тому +1

    Hello Adam. Thank you for the tutorial. I like to graph two o more categorical variables in the x axis. Is that possible?

    • @CharmingData
      @CharmingData  3 роки тому

      Hi Rodrigo, can you show me an image of what you mean? feel free to email me at info@charmingdata.org

  • @jimmila2405
    @jimmila2405 3 роки тому +2

    Thanks for the Tutorials - these are great. I have an issue which I get even when i copy your code from github - When i run the script, the browser opens up but it does not load anything and get the generic firefox error on the screen - Unable to connect Firefox can't establish a connection to the server at 127.0.0.1:50666. Why would this be? I followed your tutorial on intro.py which works perfectly and loads in the browser as expected but this one just doesnt load in browser for me. Any ideas?

    • @CharmingData
      @CharmingData  3 роки тому +1

      Interesting. Are your using the same Plotly version? Can you try copy-pasting the 127.... link into anther browser like chrome?

  • @Edu-qv1yj
    @Edu-qv1yj 9 місяців тому

    Congratulations on your excellent tutorial! I have a quick question: how can I add a comma or decimal point to differentiate between thousands and millions in the hover or axis?

  • @kaankorkmaz8180
    @kaankorkmaz8180 3 роки тому +1

    Thank you for the content! Is it possible to create a diverging bar chart on Plotly?

    • @CharmingData
      @CharmingData  3 роки тому

      Hi @Kaan. Yes. He does it here. www.kaggle.com/jrmistry/plotly-how-to-create-diverging-stacked-bar-chart
      Plotly documentation on the bar chart also has an example

  • @manalijain8362
    @manalijain8362 3 роки тому +1

    Hello
    Your videos and the way you explain everything made it so simple to learn Plotly Dash. Thank you so much!!
    I’m having trouble in updating the graph when “multi=True” in dropdown. Can you pl help??

    • @CharmingData
      @CharmingData  3 роки тому +1

      Sure Manali, send me your code and data so I can reproduce the error on my computer. Email me at info@charmingdata.org

  • @lucasbarrossciannimorais3357
    @lucasbarrossciannimorais3357 2 роки тому

    Hello again Adam! You've been my savior lately hahaha I have another question: is there any way to make each bar in the graph a button? I want information to appear in other divs when clicking on a bar of the graph.

    • @CharmingData
      @CharmingData  2 роки тому +1

      Hi Lucas, I think you can use the graph's clickData property as an input in the callback and read the data of each bar that is clicked on.

    • @lucasbarrossciannimorais3357
      @lucasbarrossciannimorais3357 2 роки тому

      @@CharmingData It worked! thanks!

  • @kiranprakashMe
    @kiranprakashMe 2 роки тому

    Very well illustrated! Thank you so much. How do I make the bar appear when y = 0? It just leaves a gap. Is there a way I can enable it to plot even for y=0? Here is my sample code. The same code in case of Box Plot, I am able to see a line on the x-axis at y=0. I would like to see this in the Bar as well.
    import plotly.graph_objects as go
    fig = go.Figure()
    fig.add_trace(go.Bar(x=[1, 2, 3], y=[0, 3, 2]))
    fig.show()

  • @mauromelonicecconi5731
    @mauromelonicecconi5731 2 роки тому

    Thanks you very much Adam! I am wondering if you could explain how to add a second trace along with a second y axes...of course using Plotly Express :) In adavance, many thanks. Mauro.

    • @CharmingData
      @CharmingData  2 роки тому

      Hi Mauro, thanks for the suggestion.

  • @VinnyBloos
    @VinnyBloos 3 роки тому

    I'm using a callback to create a bar chart and I have a list that I use to fill my hover data with information. However, this list is too big and when the information in the hover data goes pass an X amount of text, the hover data stops working. Do you know if it is possible to add a scroll wheel/slider to the hover data? Would it be possible for you to create a video on this topic?

  • @johnmay8220
    @johnmay8220 2 роки тому

    Excellent.... Question on facets. In the Plotly Express reference doc see this snippet. There is no "company" column. How can this be?

    • @CharmingData
      @CharmingData  2 роки тому

      Hi John, I'm not sure I understand. Where is the company column missing?

  • @jin-zewu7556
    @jin-zewu7556 3 роки тому

    Hi,
    Can it change y axis unit to percentage(%) instead of value?
    Is there any method like that?

    • @CharmingData
      @CharmingData  3 роки тому +1

      hi Jin-Ze, try to change the values to percentages in the pandas dataframe. Then plot it on the bar graph

  • @ramwarutkar4364
    @ramwarutkar4364 2 роки тому

    Is it possible to superimpose bar chart on stacked bar chart

  • @dominickgalang9974
    @dominickgalang9974 3 роки тому

    Great tutorial. Fyi, it appears setting color_continuous_midpoint overrides range_color. (You can set one or the other, not both.)

    • @CharmingData
      @CharmingData  3 роки тому

      Thank you, @Dominick. Maybe it's because I was using an old version of Plotly at the time. Thanks for pointing this out.

  • @tattoo3dsimulation625
    @tattoo3dsimulation625 4 роки тому

    Hi. I tried to add more than one trace to chart. However the animation_frame (Slider) doesn't work with 2 or 3 traces. I would appreciate if you could help. Thanks

    • @CharmingData
      @CharmingData  4 роки тому

      Of course. I'd be happy to, but I would need your code to see how best to help. Feel free to send me your code via plotly forum. You can find me under the same Charming Data name. community.plotly.com/

  • @Portuenllamas
    @Portuenllamas 2 роки тому

    Is there a way to increase the size of the text above the bar plots?

    • @CharmingData
      @CharmingData  2 роки тому +1

      Hi, yes, I think it might be here somewhere: plotly.com/python/reference/bar/#bar-textfont

    • @Portuenllamas
      @Portuenllamas 2 роки тому +1

      @@CharmingData thank you very much

  • @KalmaxOrion
    @KalmaxOrion 3 роки тому

    How to sort the x axis based on value of y axis?

  • @gabrielcardoso9620
    @gabrielcardoso9620 4 роки тому +1

    Adam, thanks for your dedication in produce this incrible video. I just want to ask you how can I modify the axis of a chart? For instance, I have a y-axis in this scale ---> 0, 5, 10, 15, and so on. But I want to modify and get this ---> 0M, 5M, 10M, 15M, and so on. I wanna put this 'M' to represent a thousands. How can I do it?

    • @CharmingData
      @CharmingData  4 роки тому

      Do you just want to modify the yticks text? The scale would change automatically if you plot data on the yaxis that is in the thousands

    • @gabrielcardoso9620
      @gabrielcardoso9620 4 роки тому

      But if I want to show the thousands like 5.000, 10.000 etc, instead of 5M and 10M, what parameter should I use? Or this is automatically and I can't change?

    • @CharmingData
      @CharmingData  4 роки тому

      @@gabrielcardoso9620 I think you can do something like this:
      fig.update_traces(hovertemplate=
      "%{y}000" ).

  • @davedave2783
    @davedave2783 4 роки тому

    Hi again,
    at 29:28 where you explain adding text into bars, I did it this way and my animation no longer shows transitions, just instantly changes.
    This only happens when I use:
    barchart.update_layout(uniformtext_minsize=20, uniformtext_mode='hide')
    I tried changing the uniformtext_mode to 'show' or False, and it didnt work, also if I remove uniformtext_mode, the uniformtext_minsize doesnt do anything anymore.
    Any ideas what is the issue?
    Thanks in advance.

    • @CharmingData
      @CharmingData  4 роки тому

      Hi Dave, I'm not sure because I tested it and it works for me. The barchart.update_layout() and the animation work fine together. Are you experiencing issues with the animation when using the barchart.update_traces() part? if so, what kind of problems are you experiencing?

    • @davedave2783
      @davedave2783 4 роки тому

      @@CharmingData
      Hi,
      Thanks for the quick response as always.
      the update_traces() and update_layout() are working fine, however when I apply this property uniformtext_minsize=20 (to increase text size) it does not work on its own, so then I have to include uniformtext_mode='hide'. HOWEVER, once the uniformtext_mode is added, my animation technically still works but the smoothness of transitions is gone, basically instead of seeing the bars replace one another in a barchart race, they just re-appear in their new positions.
      Hope this is more clear.
      Thanks
      Dave

    • @CharmingData
      @CharmingData  4 роки тому

      @@davedave2783 I tried replicating exactly what you told me but my transition is working. Would you like to send me your code via plotly forum? And I could try to replicate your code on my computer to see whether this is a bug or not.

    • @davedave2783
      @davedave2783 4 роки тому

      @@CharmingDataI would like to do that, however not sure how to send on the forum. If you could provide a link and so, I presume I would need to make an account and so.

    • @CharmingData
      @CharmingData  4 роки тому

      @@davedave2783 here's the link. community.plotly.com/ it's very easy and quick to create an account. After creating, just look for me to send me a message. I'm charming Data there too

  • @NobixLee
    @NobixLee 3 дні тому

    This is a wonderful tutorial, I am slightly disappointed because I was here specifically for interactive graphs and you skipped those.

    • @CharmingData
      @CharmingData  День тому

      my bad @nobixlee, but I do have plenty of other videos that go over interactive graphs. Also, come join the charming data community. You'll find many more opportunities to learn Plotly and Dash and even AI. charming-data.circle.com

  • @mauliknaik9520
    @mauliknaik9520 Рік тому

    Hi Adam, thanks for the tutorial, as always, nice one.
    I have a question. In fact I am struggling with this issue when I am using bar chart for my DASH application.
    To highlight the issue you can refer to the timestamp 10:47 (in your video) when you were illustrating the use of color_discrete_map option.
    Actually when we are using that option the bar chart is breaking. Even in your chart you can see very light horizontal lines indicating breaks/group. In fact if you see the hover information for the bar it is showing the information for the sub-group not the entire group. Like in your case when in video you hover on the 2008 the convicts for male shown is 3182 that is way below than the convicts of "male" as a group. Is this is bug for bar graph in express or is there something going behind the scene which I may not be aware of.
    I have checked the community page and various DASH tutorial but I do not get the answer to this issue.
    Thanks in Advance for your response.
    Maulik

    • @CharmingData
      @CharmingData  Рік тому

      Hi Maulik, I just ran the code and used the color_discrete_map attirbute, but didn't see anything break. Can you please repeat what exactly broke for you?

    • @mauliknaik9520
      @mauliknaik9520 Рік тому

      @@CharmingData , Hi Adam, my hypothesis of the bar graph breaking because of the color_discrete_map option might not be accurate or not conveying the main issue. But let me try to highlight my concern taking a snapshot of your video (timestamp 10:47)
      You can find the snapshot on this link drive.google.com/file/d/1CEQw9nNTtiDYQn7xRsymLWqhRjxdA2Zf/view?usp=sharing
      As you would see when I say "breaking" I want to suggest that with in the "grey" and "red" blocks of bars there are sub groups created with thin white lines and when you hover the cursor the hover data shows the values for that subgroup not the entire block (like the number of convicts for the entire grey block).
      I think it is not an issue with the color_discrete_map but an issue with the bar_garph itself when plotting for big ranges of data (again that is my hypothesis).
      Hope this explains the issue better!
      Cheers!
      Maulik

    • @mauliknaik9520
      @mauliknaik9520 Рік тому

      Hi Adam, did you had a chance to look at the issue?

    • @CharmingData
      @CharmingData  Рік тому

      @@mauliknaik9520 hi Maulik, I have some time this week. I just sent you access request to the code.

    • @CharmingData
      @CharmingData  Рік тому

      @@mauliknaik9520 hi Maulik, thank you for sharing the image. I'm not getting your graph. I'm getting the correct graph with the correct hover. Can you send me the exact code that is producing the error for you to adam@charming-data.com

  • @kahinakram5814
    @kahinakram5814 2 роки тому

    Hello Mr. Charming, I have done a ton of googling for this simple question; is there a way to create a histogram matrix in dash (like hist in matplotlib)? I have not found anything yet... do you have an answer? If so, how do I do it? Thank you.

    • @CharmingData
      @CharmingData  2 роки тому

      Hi @Kahin. no I don't think that is possible with Dash or Plotly by default.

  • @kelum0823
    @kelum0823 3 роки тому

    Thank you so much..
    Is it possible to show y-axis tick mark values 1. in thousand (K) format?
    2. with a comma for a thousand separator?
    barchart.update_layout(
    yaxis = dict(
    tickformat = '.0f'
    )

    • @CharmingData
      @CharmingData  3 роки тому +1

      Hi @Kelum, I'm on vacation now, but remind me to show you next week when I'm back. I'm on vacation away from my computer this week

    • @kelum0823
      @kelum0823 3 роки тому

      Hi @@CharmingData Appreciate it if you can help

    • @CharmingData
      @CharmingData  3 роки тому +1

      @@kelum0823 Hi @Kelum, try doing this and let me know if it works:
      barchart.update_layout(yaxis=dict(separatethousands=True))

    • @kelum0823
      @kelum0823 3 роки тому

      @@CharmingData Thanks you so much, It worked and easy to read with the thousand separators.
      Great if there a method to show values in thousands (K) format. eg. 10K for 10,000.00

    • @CharmingData
      @CharmingData  3 роки тому +1

      @@kelum0823 yes. I think that's possible as well. Let me know if you can find it in the documentation

  • @chakchakaa
    @chakchakaa Рік тому

    Sir, I'm using vs code, I got this error " 'px' is not defined ". Even though I install all those modules. What might be the solution of this problem Sir? thank you.

  • @anandakrishnangopalakrishn1961
    @anandakrishnangopalakrishn1961 2 роки тому

    thanks for the video, im unable to see the graph when my dataframe row is of 1.13 million.

  • @dab30012151227
    @dab30012151227 4 роки тому

    Hi.. nice tutorial.. do you have any tutorial for grouped bar plot using plotly.graph_objs?

    • @CharmingData
      @CharmingData  4 роки тому

      hi Dab. Thank you. I don't have that specific tutorial, but Plotly has very good examples. See here: plotly.com/python/bar-charts/

    • @dab30012151227
      @dab30012151227 4 роки тому

      @@CharmingData thank you.. i will check.

    • @dab30012151227
      @dab30012151227 4 роки тому

      @@CharmingData Hi again.. actually while passing Y axis value, i am struggling. It should show all serious and non serious in separate bars for respective Age groups. Any suggestion will be helpful.
      bar1= df['Age Group'].unique()
      #array(['Elderly', 'Adult', 'Child'], dtype=object)
      fig = go.Figure(data=[
      go.Bar(name='Serious', x=bar1, y=?),
      go.Bar(name='Non Serious', x=bar1, y=?)
      ])

    • @CharmingData
      @CharmingData  4 роки тому

      @@dab30012151227 hi, I'm really not sure what the problem is. Do you want to post your full code on Plotly forum. That way, I can replicate your code on my computer and see how to fix it.

    • @dab30012151227
      @dab30012151227 4 роки тому

      @@CharmingData never mind I solved it :) thanks

  • @utica2burn
    @utica2burn 2 роки тому

    Nothing mentioned here about binning. That's a shame as it's often the most important part of using bar charts.

  • @arpandas5641
    @arpandas5641 3 роки тому

    that one dislike might be from an indian.