Udemy Visualization Flashcards

(31 cards)

1
Q

When using jupyter notebook, how can you see plots that you create with matplotlib?

A

%matplotlib inline

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

Object-oriented way to make an x, y line plot using matplotlib

A

fig = plt.figure() #essentially creates an empty canvas

axes = fig.add_axes([0.1, 0.1, 0.8, 0.8])

axes.plot(x, y)-===============================

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

Object-oriented way to create subplots using matplotlib

A

fig, axes = plt.subplots(nrows=1, ncols=2)

axes[0].plot(x,y)

axes[0].set_title(‘First Plot’)

axes[1].plot(y, x)

axes[1].set_title(‘Second Plot’)

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

What usually takes cares of overlapping plots?

A

plt.tight_layout()

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

How can you control the figure size?

A

fig = plt.figure(figsize=(width, height))

fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(width, height))

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

How do you save a figure?

A

fig.savefig(‘my_picture.png’, dpi=200)

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

Object-oriented way to add y and x label and title

A

ax. set_ylabel(‘Y’)
ax. set_xlabel(‘X’)
ax. set_title(‘Title’)

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

How to add a legend

A

Add label to each plot and follow with ax.legend()

fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax. plot(x, x**2, label =‘X Squared’)
ax. plot(x, x**3, label =‘X Cubed’)

ax.legend()

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

How do you change position of the legend?

A

number 0-10 for different positions. Use 0 to make it find the “best” location

ax.legend(loc = number)

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

How do you add color to a line plot?

A

color can be color name, e.g. ‘green’, or RGB Hex Code starting with

ax.plot(x, y, color = ‘color’)

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

How do you modify the line width and transparency?

A

alpha defines transparency

ax.plot(x, y, linewidth = num, alpha = num)

or

ax.plot(x, y, lw = num, alpha = num)

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

How do you modify the linestyle?

A

style looks like ‘–’ or ‘:’ . More styles available

ax.plot(x, y, linestyle = ‘style’)

or

ax.plot(x, y, ls = ‘style’)

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

How do you add markers to each point on a line plot?

How do you modify the marker size?

A

Several marker styles available

ax.plot(x, y, marker = ‘marker’, markersize = num)

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

How do you set the max num in the x and y axes?

A

ax. set_xlim([lower, upper])
ax. set_ylim([lower, upper])

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

seaborn is built on top of

A

matplotlib

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

How do you make a histogram with seaborn?

A

This will also plot a kde on top unless set kde = False

sns.distplot(df[col1], bins=num)

17
Q

Use seasborn to compare distributions of two variables

A

kind=scatter is default, can also use ‘reg’ for regression line, etc

sns.jointplot(x=’col1’, y=’col2’, data=df, kind=’scatter’)

18
Q

How do you plot pairwise relationships across entire dataframe in Seaborn?

A

will produce scatter plots for all pairs of numerical values

sns.pairplot(df)

sns.pairplot(df, hue=’col2’)

19
Q

Draw dash mark for every single point in col1 to show distribution using Seaborn

A

sns.rugplot(df[‘col1’])

20
Q

Draw KDE plot using Seaborn

A

sns.kdeplot(df[‘col1’])

21
Q

Create a barplot using Seaborn

A

x is categorical, y is numerical

sns.barplot(x=’col1’, y=’col2’, data=df)

22
Q

Make a barplot of the counts of a categorical variable using Seaborn

A

sns.countplot(x=’col1’, data=df)

23
Q

Make a boxplot using Seaborn

A

x is categorical, y is numerical

sns.boxplot(x=’col1’, y=’col2’, data=df, hue=’col3’)

24
Q

Create violinplot using Seaborn

A

x is categorical, y is numerical

sns.violinplot(x=’col1’, y=’col2’, data=df)

25
Create a striplot using seaborn
sns.stripplot(x='col1', y='col2', data=df, jitter=True) #x is categorical, y is numerical #add jitter=True to separate out points
26
Create a swarmplot using Seaborn
sns.swarmplot(x='col1', y='col2', data=df) #Combo of striplot and violin plot
27
what does sns.factorplot do?
It allows you to create any kind of plot with its kind= option
28
for a heatmap to work properly, data should be in what form?
Matrix form. Can either use df.corr() or pivot table method to turn df into matrix
29
Heatmap and clustermap using seaborn
sns. heatmap(matrix) sns. clustermap(matrix)
30
Create a simple regression plot with Seaborn
sns.lmplot(x='col1', y='col2', data=df)
31
how can you look up the palettes used in seaborn?
Google matplotlib colormap