Bar Plot from a dictionary with tuple keys









up vote
3
down vote

favorite












I have a dictionary with tuple as keys, like shown below:



('Friday', 0): 108, ('Friday', 1): 110, ('Friday', 2): 75, ... ('Sunday', 23): 120


I`m trying to build a Bar plot, that with the dictionary keys in x axis and dictionary values in Y axis:



trace0 = go.Bar(
x=pump_dry_day_beh_dic.keys(),
y=pump_dry_day_beh_dic.values(),
name ='yyy'

)

fig = tools.make_subplots(rows=1, cols=1, specs=[[]],
shared_xaxes=True, shared_yaxes=True,
vertical_spacing=0.001)

fig.append_trace(trace0, 1, 1)
fig.append_trace(trace1, 1, 1)

fig['layout'].update(height=600, width=1000, title='xxx')
fig['layout']['xaxis1'].update(title='day-hour')
fig['layout']['yaxis1'].update(title='Values')
plotly.offline.iplot(fig, filename=' xxx')


But I`m getting the following error:



 The 'x' property is an array that may be specified as a tuple,
list, numpy array, or pandas Series


On the other hand, if I change the above code to the code below, I have as result an empty plot.



 x=list(pump_dry_day_beh_dic.keys()),
y=list(pump_dry_day_beh_dic.values()),
name ='yyyy'


Is there a way how I can solve this?



Thank you,










share|improve this question



























    up vote
    3
    down vote

    favorite












    I have a dictionary with tuple as keys, like shown below:



    ('Friday', 0): 108, ('Friday', 1): 110, ('Friday', 2): 75, ... ('Sunday', 23): 120


    I`m trying to build a Bar plot, that with the dictionary keys in x axis and dictionary values in Y axis:



    trace0 = go.Bar(
    x=pump_dry_day_beh_dic.keys(),
    y=pump_dry_day_beh_dic.values(),
    name ='yyy'

    )

    fig = tools.make_subplots(rows=1, cols=1, specs=[[]],
    shared_xaxes=True, shared_yaxes=True,
    vertical_spacing=0.001)

    fig.append_trace(trace0, 1, 1)
    fig.append_trace(trace1, 1, 1)

    fig['layout'].update(height=600, width=1000, title='xxx')
    fig['layout']['xaxis1'].update(title='day-hour')
    fig['layout']['yaxis1'].update(title='Values')
    plotly.offline.iplot(fig, filename=' xxx')


    But I`m getting the following error:



     The 'x' property is an array that may be specified as a tuple,
    list, numpy array, or pandas Series


    On the other hand, if I change the above code to the code below, I have as result an empty plot.



     x=list(pump_dry_day_beh_dic.keys()),
    y=list(pump_dry_day_beh_dic.values()),
    name ='yyyy'


    Is there a way how I can solve this?



    Thank you,










    share|improve this question

























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I have a dictionary with tuple as keys, like shown below:



      ('Friday', 0): 108, ('Friday', 1): 110, ('Friday', 2): 75, ... ('Sunday', 23): 120


      I`m trying to build a Bar plot, that with the dictionary keys in x axis and dictionary values in Y axis:



      trace0 = go.Bar(
      x=pump_dry_day_beh_dic.keys(),
      y=pump_dry_day_beh_dic.values(),
      name ='yyy'

      )

      fig = tools.make_subplots(rows=1, cols=1, specs=[[]],
      shared_xaxes=True, shared_yaxes=True,
      vertical_spacing=0.001)

      fig.append_trace(trace0, 1, 1)
      fig.append_trace(trace1, 1, 1)

      fig['layout'].update(height=600, width=1000, title='xxx')
      fig['layout']['xaxis1'].update(title='day-hour')
      fig['layout']['yaxis1'].update(title='Values')
      plotly.offline.iplot(fig, filename=' xxx')


      But I`m getting the following error:



       The 'x' property is an array that may be specified as a tuple,
      list, numpy array, or pandas Series


      On the other hand, if I change the above code to the code below, I have as result an empty plot.



       x=list(pump_dry_day_beh_dic.keys()),
      y=list(pump_dry_day_beh_dic.values()),
      name ='yyyy'


      Is there a way how I can solve this?



      Thank you,










      share|improve this question















      I have a dictionary with tuple as keys, like shown below:



      ('Friday', 0): 108, ('Friday', 1): 110, ('Friday', 2): 75, ... ('Sunday', 23): 120


      I`m trying to build a Bar plot, that with the dictionary keys in x axis and dictionary values in Y axis:



      trace0 = go.Bar(
      x=pump_dry_day_beh_dic.keys(),
      y=pump_dry_day_beh_dic.values(),
      name ='yyy'

      )

      fig = tools.make_subplots(rows=1, cols=1, specs=[[]],
      shared_xaxes=True, shared_yaxes=True,
      vertical_spacing=0.001)

      fig.append_trace(trace0, 1, 1)
      fig.append_trace(trace1, 1, 1)

      fig['layout'].update(height=600, width=1000, title='xxx')
      fig['layout']['xaxis1'].update(title='day-hour')
      fig['layout']['yaxis1'].update(title='Values')
      plotly.offline.iplot(fig, filename=' xxx')


      But I`m getting the following error:



       The 'x' property is an array that may be specified as a tuple,
      list, numpy array, or pandas Series


      On the other hand, if I change the above code to the code below, I have as result an empty plot.



       x=list(pump_dry_day_beh_dic.keys()),
      y=list(pump_dry_day_beh_dic.values()),
      name ='yyyy'


      Is there a way how I can solve this?



      Thank you,







      python pandas bar-chart plotly






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 20:40









      petezurich

      3,34381632




      3,34381632










      asked Nov 9 at 19:41









      onra

      1109




      1109






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Since you have pandas tag here...



          import pandas as pd

          pump_dry_day_beh_dic = ('Friday', 0): 108, ('Friday', 1): 110,
          ('Friday', 2): 75, ('Sunday', 23): 120
          pd.DataFrame([pump_dry_day_beh_dic]).T.plot.bar()


          enter image description here






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232295%2fbar-plot-from-a-dictionary-with-tuple-keys%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote



            accepted










            Since you have pandas tag here...



            import pandas as pd

            pump_dry_day_beh_dic = ('Friday', 0): 108, ('Friday', 1): 110,
            ('Friday', 2): 75, ('Sunday', 23): 120
            pd.DataFrame([pump_dry_day_beh_dic]).T.plot.bar()


            enter image description here






            share|improve this answer
























              up vote
              3
              down vote



              accepted










              Since you have pandas tag here...



              import pandas as pd

              pump_dry_day_beh_dic = ('Friday', 0): 108, ('Friday', 1): 110,
              ('Friday', 2): 75, ('Sunday', 23): 120
              pd.DataFrame([pump_dry_day_beh_dic]).T.plot.bar()


              enter image description here






              share|improve this answer






















                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                Since you have pandas tag here...



                import pandas as pd

                pump_dry_day_beh_dic = ('Friday', 0): 108, ('Friday', 1): 110,
                ('Friday', 2): 75, ('Sunday', 23): 120
                pd.DataFrame([pump_dry_day_beh_dic]).T.plot.bar()


                enter image description here






                share|improve this answer












                Since you have pandas tag here...



                import pandas as pd

                pump_dry_day_beh_dic = ('Friday', 0): 108, ('Friday', 1): 110,
                ('Friday', 2): 75, ('Sunday', 23): 120
                pd.DataFrame([pump_dry_day_beh_dic]).T.plot.bar()


                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 19:50









                ysakamoto

                2,0741719




                2,0741719



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232295%2fbar-plot-from-a-dictionary-with-tuple-keys%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Darth Vader #20

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Ondo