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
Q

barmode = ‘group’ or barmode = ‘grouped’

A

barmode = ‘group’

26
Q

How do you name a legend?

A

In trace, name = ‘’

27
Q

How do you get a graph to go to chart studio

A

py.iplot() but you must have imported chart.studio.plotly as py

28
Q

How do you change the background color?

A

plot_bgcolor = ‘white’

29
Q

If you want to change the colour of the line in the scatter what do you use?

A

trace1 = go.Scatter(x = df1[‘date’], y = df1[‘high’], line = dict(color = ‘red’), name = ‘high’)

30
Q

When in atom, iplot or plot?

A

plot

31
Q

How do you change the settings of axis titles

A

In layout; xaxis = dict(title = ‘x’)

32
Q

How do you change the shape in a scatter?

A

Within marker dictionary; symbol =

33
Q

How do you get a line chart?

A

go.Scatter(mode = ‘lines’)

34
Q

What are the options in a line chart?

A

lines
markers
lines+markers

35
Q

How do you get a stacked barchart?

A

In layout, barmode = ‘stack’

36
Q

How do you change the orientation of a bar char to be horizontal?

A

within go.Bar orientation = ‘h’

37
Q

How do you generate multiple traces without writing it all out?

A
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
Q

How do you get a bubble chart?

A

go.Scatter(marker = dict(size = df1[‘cylinder’]))

39
Q

How do you adjust the size of the bubble?

A

Multiply / divide the values to get to a sensible number

40
Q

How do you change what what the hover contains

A

within go.Scatter(text = df[‘name’])

41
Q

How do you change the colour within a bubble chart?

A

marker = dict(color = df[‘cylinder’])

42
Q

How do you add a key to a bubble chart

A

marker = dict(showscale = True)

43
Q

How do you change which data point gets selected?

A

Within layout hovermode = ‘closest’

44
Q

How do you generate a boxplot?

A

go.Box()

45
Q

How do you mark every point on a boxplot?

A

go.Box(boxpoints = ‘all’)

46
Q

How do you space out the boxpoints to make it clearer?

A

go.Box(jitter = 0.3)

47
Q

How do you determine where the boxpoints sit on the graph?

A

go.Box(pointpos=0)

Positive is to the right, negative is to the left

48
Q

How do you show outliers in a boxplot?

A

go.Box(boxpoints = ‘outliers’)

49
Q

How do you do a histogram?

A

go.Histogram(x = df1[‘x’], xbins = dict(start = , end =, size = ))

50
Q

How do you set histogram bins?

A

xbins = dict(start = , end =, size = )

51
Q

How do you do a distributino plot?

A

fig = ff.create_distplot(hist_data, group_labels, bin_size = [])

52
Q

What do you need to import for a distribution plot?

A

import plotly.figure_factory as ff

53
Q

Can you have multiple series for distplot?

A

Yes - add them as different items within a list

54
Q

What is the code for a heatmap?

A

go.Heatmap(x = , y=, z= , colorscale = )

55
Q

To add the color for a heatmap (z=) what is the format?

A

A python list

56
Q

How do you make a python list for the colour of a heatmap?

A

df[‘x’]. values.tolist()

57
Q

How do you set the limits of the colour scale

A

go.Heatmap(x =, y=, z=, colourscale =, zmin = , zmax = )

58
Q

How do you create subplots?

A

fig = tools.make_subplots(rows = , cols =, subplot_titles=[], shared_yaxes = True)

59
Q

Once you’ve created subplot, how do you add the data?

A

fig. append_trace(trace1,1,1)

fig. append_trace(trace2,1,2)

60
Q

When using subplots, do you create the trace and figure in the normal way?

A

No you create the figure then append the data

61
Q

When using subplot, do you have to tell plotly where to put it?

A

Yes and index starts at 1