How to draw bar chart using Plotly Offline mode in python?

nizam uddin picture nizam uddin · Feb 2, 2016 · Viewed 7.9k times · Source

I have some features and values like:

food        3.4   
service     4.2  
environment 4.3 

and I want to draw a bar chart using Plotly offline mode (not registering and authenticating). So far I have the code for drawing a scattered line using Plotly's offline mode:

import plotly
print (plotly.__version__) 
from plotly.graph_objs import Scatter, Layout
plotly.offline.plot({
"data": [
    Scatter(x=[1, 2, 3, 4], y=[4, 1, 3, 7])
],
"layout": Layout(
    title="hello world"
)
})

This code opens an HTML page and draws a scattered line. How to modify it so it draws a bar chart?

Answer

Dominix picture Dominix · Feb 14, 2016
import plotly
import plotly.graph_objs

plotly.offline.plot({
"data": [
    plotly.graph_objs.Bar(x=['food','service','environment'],y=[3.4,4.2,4.3])
]
})