Skip to content

Instantly share code, notes, and snippets.

@ostwalprasad
Last active April 2, 2019 17:45
Show Gist options
  • Save ostwalprasad/2bb0623817471ea092c587e0a417f65a to your computer and use it in GitHub Desktop.
Save ostwalprasad/2bb0623817471ea092c587e0a417f65a to your computer and use it in GitHub Desktop.
import pandas as pd
import plotly
import plotly.graph_objs as go
#Read cars data from csv
data = pd.read_csv("cars.csv")
markersize = data['engine-size']/12
markercolor = data['city-mpg']
markershape = data['num-of-doors'].replace("four","square").replace("two","circle")
#Make Plotly figure
fig1 = go.Scatter3d(x=data['curb-weight'],
y=data['horsepower'],
z=data['price'],
marker=dict(size=markersize,
color=markercolor,
symbol=markershape,
opacity=0.9,
reversescale=True,
colorscale='Blues'),
line=dict (width=0.02),
mode='markers')
#Make Plot.ly Layout
mylayout = go.Layout(title="2D Plot",
scene=dict(xaxis=dict( title="curb-weight"),
yaxis=dict( title="horsepower"),
zaxis=dict(title="price")),
)
#Plot and save html
plotly.offline.plot({"data": [fig1],
"layout": mylayout},
auto_open=True,
filename=("2D Plot.html"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment