Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 818
nizam uddin Avatar asked Feb 02 '16 10:02

nizam uddin


1 Answers

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])
]
})
like image 169
Dominix Avatar answered Oct 26 '22 21:10

Dominix