Plotly Flashcards

1
Q

What do you need to import?

A
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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you set credentials?

A

chart_studio.tools.set_credentials_file(username = ‘’, api_key = ‘’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you get the notebook to show visualisations within the notebook?

A

init_notebook_mode(connected= True)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What do you need to import to work with plotly offline?

A

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you generate a plot?

A

iplot(list or dictionary)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you generate a scatter plot?

A

trace = go.Scatter(
x = example_x,
y = example_y,
mode = ‘markers’)

z = [trace]

iplot(z)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you plot a pie chart?

A
fruit = ['apple', 'banana', 'cherry']
cost = [5,3,2]

trace = go.Pie(
labels = fruit,
values = cost)

z = [trace]

iplot(z)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you get a tooltip on a pie chart?

A

hoverinfo = ‘label’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you affect the data labels in a pie charts

A

textinfo = ‘label’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the different options in hover and text info?

A

‘label+value+percent’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the code to change the colours in a pie chart?

A

marker = dict(colors = z)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What mode do you need to set to get a scatter to not have a line?

A

mode = ‘markers’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the constituent parts of a graph?

A

trace (aka the data)
the layout
the figure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you code the layout?

A

layout = go.Layout()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you code the figure?

A

figure = go.Figure(data = [], layout = )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you plot a figure?

A

iplot(figure, filename = ‘test’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What can you use within go.Layout?

A

title =

showlegend =

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How do you generate a bar char?

A

go.Bar(x = , y = )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Can you have multiple traces in a chart?

A

Yes - within go.Figure pass a list

go.Figure(data = [data1,data2])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do you get a grouped bar chart?

A

go.Layout(barmode = ‘group’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How do you plot a 3d scatter?

A

trace1 = go.Scatter3d()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How do you change what the scatter points look like?

A
marker = dict(
        size = 12,
        color = z,
        colorscale = 'Viridis',
        opacity = 0.8)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How do you change the margins?

A

go.Layout(margin = dict(l=0,r=0,t=0,b=0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

showlegend or show_legend?

A

showlegend

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
barmode = 'group' or barmode = 'grouped'
barmode = 'group'
26
How do you name a legend?
In trace, name = ''
27
How do you get a graph to go to chart studio
py.iplot() but you must have imported chart.studio.plotly as py
28
How do you change the background color?
plot_bgcolor = 'white'
29
If you want to change the colour of the line in the scatter what do you use?
trace1 = go.Scatter(x = df1['date'], y = df1['high'], line = dict(color = 'red'), name = 'high')
30
When in atom, iplot or plot?
plot
31
How do you change the settings of axis titles
In layout; xaxis = dict(title = 'x')
32
How do you change the shape in a scatter?
Within marker dictionary; symbol =
33
How do you get a line chart?
go.Scatter(mode = 'lines')
34
What are the options in a line chart?
lines markers lines+markers
35
How do you get a stacked barchart?
In layout, barmode = 'stack'
36
How do you change the orientation of a bar char to be horizontal?
within go.Bar orientation = 'h'
37
How do you generate multiple traces without writing it all out?
``` list = ['Strongly Agree', 'Somewhat Agree', 'Neutral', 'Somewhat Disagree','Strongly Disagree'] data = [] for x in list: trace = go.Bar( x = df1.index, y = df1[x], name = x ) data.append(trace) ```
38
How do you get a bubble chart?
go.Scatter(marker = dict(size = df1['cylinder']))
39
How do you adjust the size of the bubble?
Multiply / divide the values to get to a sensible number
40
How do you change what what the hover contains
within go.Scatter(text = df['name'])
41
How do you change the colour within a bubble chart?
marker = dict(color = df['cylinder'])
42
How do you add a key to a bubble chart
marker = dict(showscale = True)
43
How do you change which data point gets selected?
Within layout hovermode = 'closest'
44
How do you generate a boxplot?
go.Box()
45
How do you mark every point on a boxplot?
go.Box(boxpoints = 'all')
46
How do you space out the boxpoints to make it clearer?
go.Box(jitter = 0.3)
47
How do you determine where the boxpoints sit on the graph?
go.Box(pointpos=0) Positive is to the right, negative is to the left
48
How do you show outliers in a boxplot?
go.Box(boxpoints = 'outliers')
49
How do you do a histogram?
go.Histogram(x = df1['x'], xbins = dict(start = , end =, size = ))
50
How do you set histogram bins?
xbins = dict(start = , end =, size = )
51
How do you do a distributino plot?
fig = ff.create_distplot(hist_data, group_labels, bin_size = [])
52
What do you need to import for a distribution plot?
import plotly.figure_factory as ff
53
Can you have multiple series for distplot?
Yes - add them as different items within a list
54
What is the code for a heatmap?
go.Heatmap(x = , y=, z= , colorscale = )
55
To add the color for a heatmap (z=) what is the format?
A python list
56
How do you make a python list for the colour of a heatmap?
df['x']. values.tolist()
57
How do you set the limits of the colour scale
go.Heatmap(x =, y=, z=, colourscale =, zmin = , zmax = )
58
How do you create subplots?
fig = tools.make_subplots(rows = , cols =, subplot_titles=[], shared_yaxes = True)
59
Once you've created subplot, how do you add the data?
fig. append_trace(trace1,1,1) | fig. append_trace(trace2,1,2)
60
When using subplots, do you create the trace and figure in the normal way?
No you create the figure then append the data
61
When using subplot, do you have to tell plotly where to put it?
Yes and index starts at 1