Plotting histogram on python with dictionary [duplicate]












1
















This question already has an answer here:




  • python: plot a bar using matplotlib using a dictionary

    5 answers




I want to plot the following dictionary on python using matplotlib.pyplot as a histogram.
How can I code it up?



{'G': 198, 'T': 383, 'C': 260, 'A': 317}









share|improve this question















marked as duplicate by ImportanceOfBeingErnest matplotlib
Users with the  matplotlib badge can single-handedly close matplotlib questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 13:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    1
















    This question already has an answer here:




    • python: plot a bar using matplotlib using a dictionary

      5 answers




    I want to plot the following dictionary on python using matplotlib.pyplot as a histogram.
    How can I code it up?



    {'G': 198, 'T': 383, 'C': 260, 'A': 317}









    share|improve this question















    marked as duplicate by ImportanceOfBeingErnest matplotlib
    Users with the  matplotlib badge can single-handedly close matplotlib questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 22 '18 at 13:34


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      1












      1








      1









      This question already has an answer here:




      • python: plot a bar using matplotlib using a dictionary

        5 answers




      I want to plot the following dictionary on python using matplotlib.pyplot as a histogram.
      How can I code it up?



      {'G': 198, 'T': 383, 'C': 260, 'A': 317}









      share|improve this question

















      This question already has an answer here:




      • python: plot a bar using matplotlib using a dictionary

        5 answers




      I want to plot the following dictionary on python using matplotlib.pyplot as a histogram.
      How can I code it up?



      {'G': 198, 'T': 383, 'C': 260, 'A': 317}




      This question already has an answer here:




      • python: plot a bar using matplotlib using a dictionary

        5 answers








      python matplotlib histogram






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 13:26









      Joe

      6,05421429




      6,05421429










      asked Nov 22 '18 at 13:23









      MohitMohit

      112




      112




      marked as duplicate by ImportanceOfBeingErnest matplotlib
      Users with the  matplotlib badge can single-handedly close matplotlib questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 22 '18 at 13:34


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by ImportanceOfBeingErnest matplotlib
      Users with the  matplotlib badge can single-handedly close matplotlib questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 22 '18 at 13:34


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          3 Answers
          3






          active

          oldest

          votes


















          2














          The histogram would be needed if you did not know the frequency of each item. That is, if you had data of the form



          G G T G C A A T G


          Since you already know the frequencies, it is just a simple bar plot



          {'G': 198, 'T': 383, 'C': 260, 'A': 317}
          labels, values = zip(*data.items())
          plt.bar(labels, values)





          share|improve this answer































            1














            You can simply use:



            plt.bar(data.keys(), data.values())


            enter image description here






            share|improve this answer































              0














              With pandas:



              d = {'G': 198, 'T': 383, 'C': 260, 'A': 317}
              df = pd.DataFrame({x:[y] for x,y in d.iteritems()}).T
              df.plot(kind='bar')
              plt.show()


              enter image description here






              share|improve this answer






























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                2














                The histogram would be needed if you did not know the frequency of each item. That is, if you had data of the form



                G G T G C A A T G


                Since you already know the frequencies, it is just a simple bar plot



                {'G': 198, 'T': 383, 'C': 260, 'A': 317}
                labels, values = zip(*data.items())
                plt.bar(labels, values)





                share|improve this answer




























                  2














                  The histogram would be needed if you did not know the frequency of each item. That is, if you had data of the form



                  G G T G C A A T G


                  Since you already know the frequencies, it is just a simple bar plot



                  {'G': 198, 'T': 383, 'C': 260, 'A': 317}
                  labels, values = zip(*data.items())
                  plt.bar(labels, values)





                  share|improve this answer


























                    2












                    2








                    2







                    The histogram would be needed if you did not know the frequency of each item. That is, if you had data of the form



                    G G T G C A A T G


                    Since you already know the frequencies, it is just a simple bar plot



                    {'G': 198, 'T': 383, 'C': 260, 'A': 317}
                    labels, values = zip(*data.items())
                    plt.bar(labels, values)





                    share|improve this answer













                    The histogram would be needed if you did not know the frequency of each item. That is, if you had data of the form



                    G G T G C A A T G


                    Since you already know the frequencies, it is just a simple bar plot



                    {'G': 198, 'T': 383, 'C': 260, 'A': 317}
                    labels, values = zip(*data.items())
                    plt.bar(labels, values)






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 22 '18 at 13:31









                    blue_noteblue_note

                    11.8k32434




                    11.8k32434

























                        1














                        You can simply use:



                        plt.bar(data.keys(), data.values())


                        enter image description here






                        share|improve this answer




























                          1














                          You can simply use:



                          plt.bar(data.keys(), data.values())


                          enter image description here






                          share|improve this answer


























                            1












                            1








                            1







                            You can simply use:



                            plt.bar(data.keys(), data.values())


                            enter image description here






                            share|improve this answer













                            You can simply use:



                            plt.bar(data.keys(), data.values())


                            enter image description here







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 22 '18 at 13:36









                            yatuyatu

                            11.7k31238




                            11.7k31238























                                0














                                With pandas:



                                d = {'G': 198, 'T': 383, 'C': 260, 'A': 317}
                                df = pd.DataFrame({x:[y] for x,y in d.iteritems()}).T
                                df.plot(kind='bar')
                                plt.show()


                                enter image description here






                                share|improve this answer




























                                  0














                                  With pandas:



                                  d = {'G': 198, 'T': 383, 'C': 260, 'A': 317}
                                  df = pd.DataFrame({x:[y] for x,y in d.iteritems()}).T
                                  df.plot(kind='bar')
                                  plt.show()


                                  enter image description here






                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    With pandas:



                                    d = {'G': 198, 'T': 383, 'C': 260, 'A': 317}
                                    df = pd.DataFrame({x:[y] for x,y in d.iteritems()}).T
                                    df.plot(kind='bar')
                                    plt.show()


                                    enter image description here






                                    share|improve this answer













                                    With pandas:



                                    d = {'G': 198, 'T': 383, 'C': 260, 'A': 317}
                                    df = pd.DataFrame({x:[y] for x,y in d.iteritems()}).T
                                    df.plot(kind='bar')
                                    plt.show()


                                    enter image description here







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 22 '18 at 13:35









                                    JoeJoe

                                    6,05421429




                                    6,05421429















                                        Popular posts from this blog

                                        "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                                        Alcedinidae

                                        Origin of the phrase “under your belt”?