In [2]:
import plotly
plotly.offline.init_notebook_mode();
import plotly.graph_objs as go

import pandas as pd

# Read data from a csv
z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv')

data = [
    go.Surface(
        z=z_data.as_matrix()
    )
]
layout = go.Layout(
    title='Mt Bruno Elevation',
    autosize=False,
    width=800,
    height=800,
    margin=dict(
        l=65,
        r=50,
        b=65,
        t=90
    )
)
fig = go.Figure(data=data, layout=layout)
plotly.offline.iplot(fig, filename='elevations-3d-surface')



In [ ]:


In [4]:
import plotly
plotly.offline.init_notebook_mode();
import pandas as pd

# The datasets' url. Thanks Jennifer Bryan!
url_csv = 'http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt'

df = pd.read_csv(url_csv, sep='\t')
df.head()

countries = ['China', 'India', 'United States', 'Bangladesh', 'South Africa']
fill_colors = ['#66c2a5', '#fc8d62', '#8da0cb', '#e78ac3', '#a6d854']
gf = df.groupby('country')

data = []

for country, fill_color in zip(countries[::-1], fill_colors):
    group = gf.get_group(country)
    years = group['year'].tolist()
    length = len(years)
    country_coords = [country] * length
    pop = group['pop'].tolist()
    zeros = [0] * length
    
    data.append(dict(
        type='scatter3d',
        mode='lines',
        x=years + years[::-1] + [years[0]],  # year loop: in incr. order then in decr. order then years[0]
        y=country_coords * 2 + [country_coords[0]],
        z=pop + zeros + [pop[0]],
        name='',
        surfaceaxis=1, # add a surface axis ('1' refers to axes[1] i.e. the y-axis)
        surfacecolor=fill_color,
        line=dict(
            color='black',
            width=4
        ),
    ))

layout = dict(
    title='Population from 1957 to 2007 [Gapminder]',
    showlegend=False,
    scene=dict(
        xaxis=dict(title=''),
        yaxis=dict(title=''),
        zaxis=dict(title=''),
        camera=dict(
            eye=dict(x=-1.7, y=-1.7, z=0.5)
        )
    )
)

fig = dict(data=data, layout=layout)

# IPython notebook
# py.iplot(fig, filename='filled-3d-lines')

plotly.offline.iplot(fig, filename='filled-3d-lines')



In [6]:
import plotly
plotly.offline.init_notebook_mode();
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/alpha_shape.csv')
df.head()

scatter = dict(
    mode = "markers",
    name = "y",
    type = "scatter3d",    
    x = df['x'], y = df['y'], z = df['z'],
    marker = dict( size=2, color="rgb(23, 190, 207)" )
)
clusters = dict(
    alphahull = 7,
    name = "y",
    opacity = 0.1,
    type = "mesh3d",    
    x = df['x'], y = df['y'], z = df['z']
)
layout = dict(
    title = '3d point clustering',
    scene = dict(
        xaxis = dict( zeroline=False ),
        yaxis = dict( zeroline=False ),
        zaxis = dict( zeroline=False ),
    )
)
fig = dict( data=[scatter, clusters], layout=layout )
# Use py.iplot() for IPython notebook
plotly.offline.iplot(fig, filename='3d point clustering')



In [4]:



---------------------------------------------------------------------------
PlotlyRequestError                        Traceback (most recent call last)
<ipython-input-4-43cfbafc0240> in <module>()
      1 import plotly
      2 plotly.offline.init_notebook_mode()
----> 3 figure = plotly.plotly.get_figure('https://plot.ly/~prashasti/7')
      4 print figure

/home/palashkulshreshtha/anaconda2/lib/python2.7/site-packages/plotly/plotly/plotly.pyc in get_figure(file_owner_or_url, file_id, raw)
    456 
    457     fid = '{}:{}'.format(file_owner, file_id)
--> 458     response = v2.plots.content(fid, inline_data=True)
    459     figure = response.json()
    460     if six.PY2:

/home/palashkulshreshtha/anaconda2/lib/python2.7/site-packages/plotly/api/v2/plots.pyc in content(fid, share_key, inline_data, map_data)
     52     params = make_params(share_key=share_key, inline_data=inline_data,
     53                          map_data=map_data)
---> 54     return request('get', url, params=params)
     55 
     56 

/home/palashkulshreshtha/anaconda2/lib/python2.7/site-packages/retrying.pyc in wrapped_f(*args, **kw)
     47             @six.wraps(f)
     48             def wrapped_f(*args, **kw):
---> 49                 return Retrying(*dargs, **dkw).call(f, *args, **kw)
     50 
     51             return wrapped_f

/home/palashkulshreshtha/anaconda2/lib/python2.7/site-packages/retrying.pyc in call(self, fn, *args, **kwargs)
    204 
    205             if not self.should_reject(attempt):
--> 206                 return attempt.get(self._wrap_exception)
    207 
    208             delay_since_first_attempt_ms = int(round(time.time() * 1000)) - start_time

/home/palashkulshreshtha/anaconda2/lib/python2.7/site-packages/retrying.pyc in get(self, wrap_exception)
    245                 raise RetryError(self)
    246             else:
--> 247                 six.reraise(self.value[0], self.value[1], self.value[2])
    248         else:
    249             return self.value

/home/palashkulshreshtha/anaconda2/lib/python2.7/site-packages/retrying.pyc in call(self, fn, *args, **kwargs)
    198         while True:
    199             try:
--> 200                 attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
    201             except:
    202                 tb = sys.exc_info()

/home/palashkulshreshtha/anaconda2/lib/python2.7/site-packages/plotly/api/v2/utils.pyc in request(method, url, **kwargs)
    164         status_code = response.status_code if response else None
    165         content = response.content if response else 'No content'
--> 166         raise exceptions.PlotlyRequestError(message, status_code, content)
    167     validate_response(response)
    168     return response

PlotlyRequestError: ('Connection broken: IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))

In [ ]: