How to plot IBM Watson NLU API JSON output using Plotly?
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
add a comment |
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
1
When posing example, use text rather than images.
– Simon O'Doherty
Nov 18 '18 at 1:36
add a comment |
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
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
python api plotly ibm-watson
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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:

add a comment |
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

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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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:

add a comment |
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:

add a comment |
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:

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:

answered Nov 19 '18 at 11:30
Simon O'DohertySimon O'Doherty
7,74812143
7,74812143
add a comment |
add a comment |
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

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
add a comment |
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

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
add a comment |
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

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

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
edited Nov 19 '18 at 14:41
answered Nov 18 '18 at 10:46
Vidyasagar MachupalliVidyasagar Machupalli
1,0391716
1,0391716
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
When posing example, use text rather than images.
– Simon O'Doherty
Nov 18 '18 at 1:36