How to draw a histogram using Plotly Offline mode in Python?

I have some features and values, such as:

food 3.4 service 4.2 environment 4.3 

and I want to draw a histogram offline Plotly (without registration and authentication). So far I have the code for drawing a scattered line offline Plotly:

 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 dashed line. How to change it so that it draws a histogram?

+8
source share
3 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]) ] }) 
+10
source

To plot offline, use:

 # Import package import plotly # Use init_notebook_mode() to view the plots in jupyter notebook plotly.offline.init_notebook_mode() from plotly.graph_objs import Scatter,Layout,Bar trace1 = Bar(x=['food','service','environment'],y=[3.4,4.2,4.3]) # Create chart plotly.offline.iplot({ "data": [ trace1 ], "layout": Layout(title="<b>Sample_Title</b>",xaxis= dict( title= '<b>X axis label</b>', zeroline= False, gridcolor='rgb(183,183,183)', showline=True ), yaxis=dict( title= '<b>Y axis Label</b>', gridcolor='rgb(183,183,183)', zeroline=False, showline=True ),font=dict(family='Courier New, monospace', size=12, color='rgb(0,0,0)')) }) 

To build stacked charts or a group chart, refer to the tutorial: https://github.com/SayaliSonawane/Plotly_Offline_Python/tree/master/Bar%20Chart

0
source

With recent story versions (I'm on 4.1.0 ), it's easier than ever.

 import plotly.graph_objects as go animals=['giraffes', 'orangutans', 'monkeys'] fig = go.Figure([go.Bar(x=animals, y=[20, 14, 23])]) fig.show() 

enter image description here

If you want to switch between, say, Jupyterlab and your web browser, you can set this up first using import plotly.io as pio and pio.renderers.default = 'jupyterlab or pio.renderers.default = 'browser' , respectively.

 import plotly.graph_objects as go import plotly.io as pio pio.renderers.default = 'browser' animals=['giraffes', 'orangutans', 'monkeys'] fig = go.Figure([go.Bar(x=animals, y=[20, 14, 23])]) fig.show() 
0
source

Source: https://habr.com/ru/post/1242081/


All Articles