Bar plot in Python using Plotly

Step 1: Install plotly package if you haven't.

Follow this article: http://com.puter.tips/2017/02/install-plotly-package-in-python.html

Step 2: Set up your online credentials for plotly account.

2.1: Go to https://plot.ly/settings/api
2.2: Sign in/sign up.
2.3: Open https://plot.ly/settings/api (API Settings page) and click on Regenerate Key button. Copy the API key.


Step 3: Run the following command from Python.

import plotly
plotly.tools.set_credentials_file(username='DemoAccount', api_key='lr1c37zw81')

Replace username and api_key with your values.

Step 4: Try the following program.

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

data = [go.Bar(
            x=['giraffes', 'orangutans', 'monkeys'],
            y=[20, 14, 23]
    )]

py.iplot(data, filename='basic-bar')

Step 5: Run and see output.


Step 6: View your plot from plotly portal and share it with others.

Hover on your plot and click on view.


This example builds a bar chart with Plotly in Python. It assumes Plotly is installed and walks through the account and credential setup that older Plotly versions required for online plotting.

Newer Plotly works fully offline by default, rendering charts locally without an account, so on current versions you can skip the credential steps and call the express or graph_objects API directly.

Comments

Popular posts from this blog

[Solved] Error: No such keg: /usr/local/Cellar/gcc

[How To] Unfollow Non-followers on Instagram