plots Flashcards

1
Q

basic bar chart

A
plt.bar(x, y)
# x is list of categoryNames
# y is list of quantity to visualize
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

basic pie chart

A
plt.pie(y, labels = x)
# x is list of categoryNames
# y is list of quantity to visualize
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Pareto chart assuming df.col1 on x axis, [‘col1_quantity’], and [‘cumpercentage’]

A

from matplotlib.ticker import PercentFormatter
fig, ax = plt.subplots(figsize=(20,10))
ax.bar(df[‘col1’], df[“col1_quantity”], color=”C0”)
ax2 = ax.twinx()
ax2.plot(df[‘col1’], df[“cumpercentage”], color=”C1”, marker=”D”, ms=7)
ax2.yaxis.set_major_formatter(PercentFormatter())
ax.tick_params(axis=”y”, colors=”C0”)
ax2.tick_params(axis=”y”, colors=”C1”)
plt.title(‘pareto chart’)
plt.show()

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

histogram with relative frequency for an array

A

plt. hist(arr, bins=10, density=True)
plt. ylabel(‘Relative Frequency’)
plt. xticks(intervals)

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

histogram with absolute frequency for an array

A

plt. figure(figsize = (20,10))
plt. hist(arr, bins=10)
plt. ylabel(‘Absolute Frequency’)
plt. xticks(intervals)

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

create side by side bar chart for two level variables. Specify what you need to do with df first.
eg, col1 is gender, col2 is country, and col3 is the quantity to visualize

A
g = sns.catplot(x='col1', y='col3', hue='col2', data=df, kind='bar')
g.fig.set_size_inches(20,10)
# need to melt df first
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

adjust seaboard settings

A

sns.set_context(“notebook”, rc={“font.size”:16,”axes.titlesize”:20,”axes.labelsize”:16})

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

basic scatter plot for arr1 and arr2

A

plt. scatter(arr1, arr2)
plt. title(“arr1 vs arr2”)
plt. show()

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

basic box plot for one array. Add optional argument to make it vertical

A

sns.boxplot(arr1, orient=’v’ )

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

basic violin plot for one array

A

sns.violinplot(arr1)

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

basic structure to create two subplots side by side

A

f, axes = plt.subplots(1, 2)

sns. boxplot(arr1, ax=axes[0] )
sns. boxplot(arr2, ax=axes[1])

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

name the x-axis using appropriate font size

A

plt.xlabel(‘TEXT’, fontsize = 20)

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

line graph with thickness of line, name of line, and color

A

plt.plot(x, yhat, lw=4, c=’orange’, label =’regression line’)

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

imports to make plots in seaboard

A

import seaborn as sns

sns.set()

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

scatter plot with regression line. independent variable is x1, dependent variable is yhat.

A

plt.scatter(x1,y)
fig = plt.plot(x1,yhat, lw=4, c=’orange’, label =’regression line’)
plt.show()

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