Skip to content

Commit 403c88e

Browse files
authored
Align exercise with lesson
1 parent 9cf4089 commit 403c88e

1 file changed

Lines changed: 27 additions & 25 deletions

File tree

lessons/11_plotting_basics-Answer_key.qmd

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ new_metadata = pd.read_csv("data/new_metadata.csv", index_col=0)
3232

3333
# Exercise 1
3434

35-
1. The current axis label text defaults to what we gave as input to `sns.scatterplot` (i.e the column headers). We can change this by **adding additional layers** called `plt.xlabel()` and `plt.ylabel()` for the x- and y-axis, respectively. Add these layers to the current plot such that the x-axis is labeled "Age (days)" and the y-axis is labeled "Mean expression".
35+
1. Add a `plt.ylabel()` layer to the current plot such that the y-axis is labeled "Mean expression".
3636

3737
```{python}
3838
#| label: exercise_1
3939
# Set the theme to "whitegrid"
40-
sns.set_style("whitegrid")
40+
sns.set_style(style = "whitegrid")
4141
4242
# Initialize a plot with a specific size
4343
plt.figure(figsize=(8, 6))
@@ -50,12 +50,12 @@ sns.scatterplot(data = new_metadata,
5050
style="celltype",
5151
s=50)
5252
53-
# Change the size of the axis label
53+
# Change the size and text of the axis label
5454
plt.xlabel(xlabel = "Age in Days",
5555
fontsize=20)
5656
57-
# Add y-axis label
58-
plt.ylabel(ylabel = "Mean Expression",
57+
# Add an plt.ylabel() layers to the current plot such that the y-axis is labeled “Mean expression”.
58+
plt.ylabel(ylabel = "Mean expression",
5959
fontsize=20)
6060
```
6161

@@ -64,7 +64,7 @@ plt.ylabel(ylabel = "Mean Expression",
6464
```{python}
6565
#| label: exercise_2
6666
# Set the theme to "whitegrid"
67-
sns.set_style("whitegrid")
67+
sns.set_style(style = "whitegrid")
6868
6969
# Initialize a plot with a specific size
7070
plt.figure(figsize=(8, 6))
@@ -77,24 +77,24 @@ sns.scatterplot(data = new_metadata,
7777
style="celltype",
7878
s=50)
7979
80-
# Change the size of the axis label
80+
# Change the size and text of the axis label
8181
plt.xlabel(xlabel = "Age in Days",
8282
fontsize=20)
8383
84-
# Add y-axis label
85-
plt.ylabel(ylabel = "Mean Expression",
84+
# Add an plt.ylabel() layers to the current plot such that the y-axis is labeled “Mean expression”.
85+
plt.ylabel(ylabel = "Mean expression",
8686
fontsize=20)
8787
88-
# Add title label to plot
89-
plt.title(label = "Mean expression vs Age (Days)")
88+
# Use the plt.title() layer to add a plot title of your choice.
89+
plt.title(label = "Mean expression by age")
9090
```
9191

9292
3. When you add the arguments `loc="right"` to the `plt.title()` function, what does it change?
9393

9494
```{python}
9595
#| label: exercise_3
9696
# Set the theme to "whitegrid"
97-
sns.set_style("whitegrid")
97+
sns.set_style(style = "whitegrid")
9898
9999
# Initialize a plot with a specific size
100100
plt.figure(figsize=(8, 6))
@@ -107,26 +107,28 @@ sns.scatterplot(data = new_metadata,
107107
style="celltype",
108108
s=50)
109109
110-
# Change the size of the axis label
110+
# Change the size and text of the axis label
111111
plt.xlabel(xlabel = "Age in Days",
112112
fontsize=20)
113113
114-
# Add y-axis label
115-
plt.ylabel(ylabel = "Mean Expression",
114+
# Add an plt.ylabel() layers to the current plot such that the y-axis is labeled “Mean expression”.
115+
plt.ylabel(ylabel = "Mean expression",
116116
fontsize=20)
117117
118-
# Add title label to plot
119-
plt.title(label = "Mean expression vs Age (Days)",
118+
# Use the plt.title() layer to add a plot title of your choice.
119+
# When you add the arguments loc="right" to the plt.title() function, what does it change?
120+
plt.title(label = "Mean expression by age",
120121
loc="right")
121122
```
122123

123-
4. Try adding the layer `plt.legend(loc="center right")` to the end of your code. What does this do? How many layers can be added to a plot, in your estimation?
124+
The title of the plot is now right-aligned.
124125

126+
4. Try adding the layer `plt.legend(loc="center right")` to the end of your code. What does this do? How many layers can be added to a plot, in your estimation?
125127

126128
```{python}
127129
#| label: exercise_4
128130
# Set the theme to "whitegrid"
129-
sns.set_style("whitegrid")
131+
sns.set_style(style = "whitegrid")
130132
131133
# Initialize a plot with a specific size
132134
plt.figure(figsize=(8, 6))
@@ -139,19 +141,19 @@ sns.scatterplot(data = new_metadata,
139141
style="celltype",
140142
s=50)
141143
142-
# Change the size of the axis label
144+
# Change the size and text of the axis label
143145
plt.xlabel(xlabel = "Age in Days",
144146
fontsize=20)
145147
146-
# Add y-axis label
147-
plt.ylabel(ylabel = "Mean Expression",
148+
# Add an plt.ylabel() layers to the current plot such that the y-axis is labeled “Mean expression”.
149+
plt.ylabel(ylabel = "Mean expression",
148150
fontsize=20)
149151
150-
# Add title label to plot
151-
plt.title(label = "Mean expression vs Age (Days)")
152+
# Use the plt.title() layer to add a plot title of your choice.
153+
plt.title(label = "Mean expression by age")
152154
153155
# Change legend location
154156
plt.legend(loc="center right")
155157
```
156158

157-
`plt.legend` changes the location of the legend in the plot. We can add as many layers as we would like.
159+
`plt.legend` changes the location of the legend in the plot. We can add as many layers as we would like.

0 commit comments

Comments
 (0)