Bar Graph -- Python Plotly

Sdílet
Vložit
  • čas přidán 3. 04. 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...

Komentáře • 113

  • @dianaamiri9520
    @dianaamiri9520 Před 3 lety +16

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

  • @yunpeng_ma
    @yunpeng_ma Před 3 lety +4

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

  • @lucass8031
    @lucass8031 Před 3 lety +3

    Thank you so much for these tutorials!

  • @gemedest3035
    @gemedest3035 Před 3 lety +4

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

    • @CharmingData
      @CharmingData  Před 3 lety +2

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

  • @tattoo3dsimulation625
    @tattoo3dsimulation625 Před 4 lety +1

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

  • @MrCaraciolo
    @MrCaraciolo Před 2 lety +1

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

  • @officesayan
    @officesayan Před 3 lety

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

    • @CharmingData
      @CharmingData  Před 3 lety

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

  • @DK-rl1sf
    @DK-rl1sf Před 2 lety

    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  Před 2 lety

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

    • @DK-rl1sf
      @DK-rl1sf Před 2 lety

      @@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.

  • @Fasodre
    @Fasodre Před 3 lety +1

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

    • @CharmingData
      @CharmingData  Před 3 lety +1

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

    • @Fasodre
      @Fasodre Před 3 lety

      ​@@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  Před 3 lety +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.

  • @abdullahansari5084
    @abdullahansari5084 Před 3 lety

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

  • @nhubanhat
    @nhubanhat Před 3 lety

    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  Před 3 lety +1

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

    • @nhubanhat
      @nhubanhat Před 3 lety

      @@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  Před 3 lety

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

  • @romanbulatnikov7157
    @romanbulatnikov7157 Před 4 lety +1

    Awesome tutorial in details!! Thanks!

    • @CharmingData
      @CharmingData  Před 4 lety

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

  • @sau953
    @sau953 Před 2 lety +1

    You sir are a Legend!

  • @davedave2783
    @davedave2783 Před 4 lety +2

    Hi Man,
    Awesome videos.
    Subscribed.

  • @ankurkumar9660
    @ankurkumar9660 Před rokem +1

    wow it's Amazing 😍😍😍😍

  • @consultoriaecoingenieros6046

    Love your tutorials

  • @SaintNath
    @SaintNath Před 3 lety

    Thanks, using this for my PhD project right now!

    • @CharmingData
      @CharmingData  Před 3 lety

      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

  • @rdurango92
    @rdurango92 Před 4 lety +1

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

    • @CharmingData
      @CharmingData  Před 4 lety +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.

  • @professionalcricketinsights

    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.

  • @johannesallgaier5722
    @johannesallgaier5722 Před 4 lety +1

    Great video. Good continent.

  • @ahmedtejanfoday3138
    @ahmedtejanfoday3138 Před 2 lety +2

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

  • @arthurh1969
    @arthurh1969 Před 2 lety

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

  • @siddarthg3214
    @siddarthg3214 Před 2 lety

    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.

  • @zulfiqarahmedcanadian
    @zulfiqarahmedcanadian Před 3 lety

    You are really grate sir

    • @CharmingData
      @CharmingData  Před 3 lety

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

  • @Aravinda_Raj
    @Aravinda_Raj Před 2 lety

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

  • @Edu-qv1yj
    @Edu-qv1yj Před 10 měsíci

    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?

  • @kiranprakashMe
    @kiranprakashMe Před 2 lety

    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()

  • @VinnyBloos
    @VinnyBloos Před 3 lety

    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?

  • @exlonkgil6465
    @exlonkgil6465 Před rokem

    I love you, a lot.

  • @rodrigoolmedo160
    @rodrigoolmedo160 Před 3 lety +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  Před 3 lety

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

  • @ramwarutkar4364
    @ramwarutkar4364 Před 2 lety

    Is it possible to superimpose bar chart on stacked bar chart

  • @kaankorkmaz8180
    @kaankorkmaz8180 Před 3 lety +1

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

    • @CharmingData
      @CharmingData  Před 3 lety

      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

  • @johnmay8220
    @johnmay8220 Před 2 lety

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

    • @CharmingData
      @CharmingData  Před 2 lety

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

  • @jimmila2405
    @jimmila2405 Před 3 lety +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  Před 3 lety +1

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

  • @BlueSkyGoldSun
    @BlueSkyGoldSun Před 2 lety

    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 !!

  • @KalmaxOrion
    @KalmaxOrion Před 3 lety

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

  • @mauromelonicecconi5731

    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.

  • @chakchakaa
    @chakchakaa Před rokem

    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.

  • @manalijain8362
    @manalijain8362 Před 3 lety +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  Před 3 lety +1

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

  • @tattoo3dsimulation625
    @tattoo3dsimulation625 Před 4 lety

    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  Před 4 lety

      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/

  • @jin-zewu7556
    @jin-zewu7556 Před 3 lety

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

    • @CharmingData
      @CharmingData  Před 3 lety +1

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

  • @lucasbarrossciannimorais3357

    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  Před 2 lety +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 Před 2 lety

      @@CharmingData It worked! thanks!

  • @anandakrishnangopalakrishn1961

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

  • @kahinakram5814
    @kahinakram5814 Před 2 lety

    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  Před 2 lety

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

  • @gabrielcardoso9620
    @gabrielcardoso9620 Před 4 lety +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  Před 4 lety

      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 Před 4 lety

      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  Před 4 lety

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

  • @Portuenllamas
    @Portuenllamas Před 2 lety

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

    • @CharmingData
      @CharmingData  Před 2 lety +1

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

    • @Portuenllamas
      @Portuenllamas Před 2 lety +1

      @@CharmingData thank you very much

  • @dominickgalang9974
    @dominickgalang9974 Před 3 lety

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

    • @CharmingData
      @CharmingData  Před 3 lety

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

  • @davedave2783
    @davedave2783 Před 4 lety

    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  Před 4 lety

      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 Před 4 lety

      @@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  Před 4 lety

      @@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 Před 4 lety

      @@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  Před 4 lety

      @@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

  • @mauliknaik9520
    @mauliknaik9520 Před rokem

    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  Před rokem

      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 Před rokem

      @@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 Před rokem

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

    • @CharmingData
      @CharmingData  Před rokem

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

    • @CharmingData
      @CharmingData  Před rokem

      @@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

  • @kelum0823
    @kelum0823 Před 3 lety

    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  Před 3 lety +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 Před 3 lety

      Hi @@CharmingData Appreciate it if you can help

    • @CharmingData
      @CharmingData  Před 3 lety +1

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

    • @kelum0823
      @kelum0823 Před 3 lety

      @@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  Před 3 lety +1

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

  • @NobixLee
    @NobixLee Před 18 dny

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

    • @CharmingData
      @CharmingData  Před 16 dny

      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

  • @dab30012151227
    @dab30012151227 Před 4 lety

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

    • @CharmingData
      @CharmingData  Před 4 lety

      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 Před 4 lety

      @@CharmingData thank you.. i will check.

    • @dab30012151227
      @dab30012151227 Před 4 lety

      @@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  Před 4 lety

      @@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 Před 4 lety

      @@CharmingData never mind I solved it :) thanks

  • @utica2burn
    @utica2burn Před 2 lety

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

  • @arpandas5641
    @arpandas5641 Před 3 lety

    that one dislike might be from an indian.