Plotly Flashcards
What do you need to import?
import plotly.graph_objs as go import chart_studio import chart_studio.plotly as py import plotly.offline as pyo from plotly import tools
How do you set credentials?
chart_studio.tools.set_credentials_file(username = ‘’, api_key = ‘’)
How do you get the notebook to show visualisations within the notebook?
init_notebook_mode(connected= True)
What do you need to import to work with plotly offline?
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
How do you generate a plot?
iplot(list or dictionary)
How do you generate a scatter plot?
trace = go.Scatter(
x = example_x,
y = example_y,
mode = ‘markers’)
z = [trace]
iplot(z)
How do you plot a pie chart?
fruit = ['apple', 'banana', 'cherry'] cost = [5,3,2]
trace = go.Pie(
labels = fruit,
values = cost)
z = [trace]
iplot(z)
How do you get a tooltip on a pie chart?
hoverinfo = ‘label’
How do you affect the data labels in a pie charts
textinfo = ‘label’
What are the different options in hover and text info?
‘label+value+percent’
What is the code to change the colours in a pie chart?
marker = dict(colors = z)
What mode do you need to set to get a scatter to not have a line?
mode = ‘markers’
What are the constituent parts of a graph?
trace (aka the data)
the layout
the figure
How do you code the layout?
layout = go.Layout()
How do you code the figure?
figure = go.Figure(data = [], layout = )
How do you plot a figure?
iplot(figure, filename = ‘test’)
What can you use within go.Layout?
title =
showlegend =
How do you generate a bar char?
go.Bar(x = , y = )
Can you have multiple traces in a chart?
Yes - within go.Figure pass a list
go.Figure(data = [data1,data2])
How do you get a grouped bar chart?
go.Layout(barmode = ‘group’
How do you plot a 3d scatter?
trace1 = go.Scatter3d()
How do you change what the scatter points look like?
marker = dict( size = 12, color = z, colorscale = 'Viridis', opacity = 0.8)
How do you change the margins?
go.Layout(margin = dict(l=0,r=0,t=0,b=0)
showlegend or show_legend?
showlegend