Tutorial: Installing and Using Plotly with Python 2.7 on macOS
This guide walks through installing Plotly via pip, setting up a Plotly account and credentials, configuring privacy options, and provides complete Python 2.7 code examples to generate and display interactive charts on macOS.
Reading font

I discovered that official Plotly tutorials were outdated for Python 2.7 on macOS, so I wrote this step‑by‑step guide.
Installation: use pip (or sudo pip, or pip install --upgrade) to install the Plotly package.
$ pip install plotly<br/>or<br/>$ sudo pip install plotly<br/>or<br/>$ pip install plotly --upgradeCreate a Plotly account and set credentials in interactive mode:
import plotly<br/>plotly.tools.set_credentials_file(username='DemoAccount', api_key='lr1c37zw81')The credentials are stored in ~/.plotly/.credentials. Example content is shown in the article.
If using Plotly online, configure privacy settings:
import plotly<br/>plotly.tools.set_config_file(world_readable=False, sharing='private')import plotly<br/>plotly.tools.set_config_file(plotly_domain='https://plotly.your-company.com', plotly_streaming_domain='stream-plotly.your-company.com')Sample script that generates random data and plots it:
#!/usr/bin/python<br/># coding=utf-8<br/><br/>import plotly.plotly<br/>import random<br/>from plotly.graph_objs import *<br/>import plotly.graph_objs as abc # must import as abc<br/><br/>listx = [];<br/>for i in range(20):<br/> listx.append(i)<br/>print listx<br/>listxx = listx<br/>listy = [];<br/>for i in range(20):<br/> listy.append(random.randint(12, 20))<br/>print listy<br/>listyy = [];<br/>for i in range(20):<br/> listyy.append(random.randint(12, 20))<br/>print listy<br/>data_1 = abc.Scatter(x=listx, y=listy)<br/>date_2 = abc.Scatter(x=listxx, y=listyy)<br/>data1 = Data([data_1, date_2])<br/>plotly.offline.plot(data1)Official test code from Plotly documentation:
import plotly.plotly as py<br/>from plotly.graph_objs import *<br/><br/>trace0 = Scatter(x=[1, 2, 3, 4], y=[10, 15, 13, 17])<br/>trace1 = Scatter(x=[1, 2, 3, 4], y=[16, 5, 11, 9])<br/>data = Data([trace0, trace1])<br/>py.plot(data, filename='basic-line')Note: the import statement import plotly.graph_objs as abc is required for the script to work.