How to plot IBM Watson NLU API JSON output using Plotly?












1















I used IBM Watson NLU API and fetched keywords from the response in JSON format. Now, I want to plot a graph by taking 'x'='text' ,'y'='count' using plotly but don't know how to do this.image










share|improve this question




















  • 1





    When posing example, use text rather than images.

    – Simon O'Doherty
    Nov 18 '18 at 1:36
















1















I used IBM Watson NLU API and fetched keywords from the response in JSON format. Now, I want to plot a graph by taking 'x'='text' ,'y'='count' using plotly but don't know how to do this.image










share|improve this question




















  • 1





    When posing example, use text rather than images.

    – Simon O'Doherty
    Nov 18 '18 at 1:36














1












1








1








I used IBM Watson NLU API and fetched keywords from the response in JSON format. Now, I want to plot a graph by taking 'x'='text' ,'y'='count' using plotly but don't know how to do this.image










share|improve this question
















I used IBM Watson NLU API and fetched keywords from the response in JSON format. Now, I want to plot a graph by taking 'x'='text' ,'y'='count' using plotly but don't know how to do this.image







python api plotly ibm-watson






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '18 at 7:32









Vidyasagar Machupalli

1,0391716




1,0391716










asked Nov 17 '18 at 17:51









Avinash KoshalAvinash Koshal

64




64








  • 1





    When posing example, use text rather than images.

    – Simon O'Doherty
    Nov 18 '18 at 1:36














  • 1





    When posing example, use text rather than images.

    – Simon O'Doherty
    Nov 18 '18 at 1:36








1




1





When posing example, use text rather than images.

– Simon O'Doherty
Nov 18 '18 at 1:36





When posing example, use text rather than images.

– Simon O'Doherty
Nov 18 '18 at 1:36












2 Answers
2






active

oldest

votes


















1














If your JSON object was called response then this sample code will convert it into a pandas dataframe and display it as a graph.



import pandas as pd
df = pd.DataFrame(response['keywords'], columns=['text', 'relevance', 'count'])
df.plot(kind='barh', x='text', y='count')


It will display something like this:



enter image description here






share|improve this answer































    0














    There’s no easy or direct way to achieve this. You may have to use a library like pandas to transform the JSON output in to format plotly can plot on a chart.



    You can start with Pandas 101 - https://plot.ly/pandas/intro-to-pandas-tutorial/



    Here's the Plotly Bar chart with text and count data plotted using Jupyter notebook on IBM Watson studio
    enter image description here



    Plotly code:



    import plotly
    import plotly.plotly as py
    import plotly.graph_objs as go

    NLU_data = [go.Bar(x=NLU_df.text, y=NLU_df['count'].tolist())]

    py.iplot({ 'data': NLU_data,
    'layout': {
    'title': 'Distribution',
    'xaxis': {
    'title': 'text'},
    'yaxis': {
    'title': 'count'}
    }})


    You can find the Jupyter notebook here with complete code for your reference






    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',
      autoActivateHeartbeat: false,
      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%2f53353927%2fhow-to-plot-ibm-watson-nlu-api-json-output-using-plotly%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      If your JSON object was called response then this sample code will convert it into a pandas dataframe and display it as a graph.



      import pandas as pd
      df = pd.DataFrame(response['keywords'], columns=['text', 'relevance', 'count'])
      df.plot(kind='barh', x='text', y='count')


      It will display something like this:



      enter image description here






      share|improve this answer




























        1














        If your JSON object was called response then this sample code will convert it into a pandas dataframe and display it as a graph.



        import pandas as pd
        df = pd.DataFrame(response['keywords'], columns=['text', 'relevance', 'count'])
        df.plot(kind='barh', x='text', y='count')


        It will display something like this:



        enter image description here






        share|improve this answer


























          1












          1








          1







          If your JSON object was called response then this sample code will convert it into a pandas dataframe and display it as a graph.



          import pandas as pd
          df = pd.DataFrame(response['keywords'], columns=['text', 'relevance', 'count'])
          df.plot(kind='barh', x='text', y='count')


          It will display something like this:



          enter image description here






          share|improve this answer













          If your JSON object was called response then this sample code will convert it into a pandas dataframe and display it as a graph.



          import pandas as pd
          df = pd.DataFrame(response['keywords'], columns=['text', 'relevance', 'count'])
          df.plot(kind='barh', x='text', y='count')


          It will display something like this:



          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 11:30









          Simon O'DohertySimon O'Doherty

          7,74812143




          7,74812143

























              0














              There’s no easy or direct way to achieve this. You may have to use a library like pandas to transform the JSON output in to format plotly can plot on a chart.



              You can start with Pandas 101 - https://plot.ly/pandas/intro-to-pandas-tutorial/



              Here's the Plotly Bar chart with text and count data plotted using Jupyter notebook on IBM Watson studio
              enter image description here



              Plotly code:



              import plotly
              import plotly.plotly as py
              import plotly.graph_objs as go

              NLU_data = [go.Bar(x=NLU_df.text, y=NLU_df['count'].tolist())]

              py.iplot({ 'data': NLU_data,
              'layout': {
              'title': 'Distribution',
              'xaxis': {
              'title': 'text'},
              'yaxis': {
              'title': 'count'}
              }})


              You can find the Jupyter notebook here with complete code for your reference






              share|improve this answer






























                0














                There’s no easy or direct way to achieve this. You may have to use a library like pandas to transform the JSON output in to format plotly can plot on a chart.



                You can start with Pandas 101 - https://plot.ly/pandas/intro-to-pandas-tutorial/



                Here's the Plotly Bar chart with text and count data plotted using Jupyter notebook on IBM Watson studio
                enter image description here



                Plotly code:



                import plotly
                import plotly.plotly as py
                import plotly.graph_objs as go

                NLU_data = [go.Bar(x=NLU_df.text, y=NLU_df['count'].tolist())]

                py.iplot({ 'data': NLU_data,
                'layout': {
                'title': 'Distribution',
                'xaxis': {
                'title': 'text'},
                'yaxis': {
                'title': 'count'}
                }})


                You can find the Jupyter notebook here with complete code for your reference






                share|improve this answer




























                  0












                  0








                  0







                  There’s no easy or direct way to achieve this. You may have to use a library like pandas to transform the JSON output in to format plotly can plot on a chart.



                  You can start with Pandas 101 - https://plot.ly/pandas/intro-to-pandas-tutorial/



                  Here's the Plotly Bar chart with text and count data plotted using Jupyter notebook on IBM Watson studio
                  enter image description here



                  Plotly code:



                  import plotly
                  import plotly.plotly as py
                  import plotly.graph_objs as go

                  NLU_data = [go.Bar(x=NLU_df.text, y=NLU_df['count'].tolist())]

                  py.iplot({ 'data': NLU_data,
                  'layout': {
                  'title': 'Distribution',
                  'xaxis': {
                  'title': 'text'},
                  'yaxis': {
                  'title': 'count'}
                  }})


                  You can find the Jupyter notebook here with complete code for your reference






                  share|improve this answer















                  There’s no easy or direct way to achieve this. You may have to use a library like pandas to transform the JSON output in to format plotly can plot on a chart.



                  You can start with Pandas 101 - https://plot.ly/pandas/intro-to-pandas-tutorial/



                  Here's the Plotly Bar chart with text and count data plotted using Jupyter notebook on IBM Watson studio
                  enter image description here



                  Plotly code:



                  import plotly
                  import plotly.plotly as py
                  import plotly.graph_objs as go

                  NLU_data = [go.Bar(x=NLU_df.text, y=NLU_df['count'].tolist())]

                  py.iplot({ 'data': NLU_data,
                  'layout': {
                  'title': 'Distribution',
                  'xaxis': {
                  'title': 'text'},
                  'yaxis': {
                  'title': 'count'}
                  }})


                  You can find the Jupyter notebook here with complete code for your reference







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 19 '18 at 14:41

























                  answered Nov 18 '18 at 10:46









                  Vidyasagar MachupalliVidyasagar Machupalli

                  1,0391716




                  1,0391716






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53353927%2fhow-to-plot-ibm-watson-nlu-api-json-output-using-plotly%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







                      這個網誌中的熱門文章

                      Academy of Television Arts & Sciences

                      L'Équipe

                      1995 France bombings