Skip to content

Commit b2166ac

Browse files
committed
minor updates in Exercise: Matplotlib
1 parent cd255c4 commit b2166ac

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

content/data-visualization.md

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ Let us create our first plot using
8080
{obj}`~matplotlib.axes.Axes.scatter`, and some other methods on the
8181
{obj}`~matplotlib.axes.Axes` object:
8282

83-
```{code-block} python
84-
# this line tells Jupyter to display matplotlib figures in the notebook
85-
%matplotlib inline
86-
83+
```python
8784
import matplotlib.pyplot as plt
8885

8986
# this is dataset 1 from
@@ -105,6 +102,7 @@ ax.set_title("some title")
105102

106103
```{figure} data-visualization/first-plot/getting-started.png
107104
:alt: Result of our first plot
105+
:width: 80%
108106
109107
This is the result of our first plot.
110108
```
@@ -134,26 +132,25 @@ matplotlib.use("Agg")
134132
by 2.0.
135133
```python
136134
# here we multiply all elements of data2_y by 2.0
137-
data2_y_scaled = [y*2.0 for y in data2_y]
135+
data2_y_scaled = [y * 2.0 for y in data2_y]
138136
```
139137
140138
- Try to add a legend to the plot with {meth}`matplotlib.axes.Axes.legend` and searching the web for clues on
141139
how to add labels to each dataset.
142140
143141
- At the end it should look like this one:
144-
```{figure} data-visualization/first-plot/exercise.png
145-
:alt: Result of the exercise
146-
```
142+
```{figure} data-visualization/first-plot/exercise.png
143+
:alt: Result of the exercise
144+
```
145+
146+
- Experiment also by using named colors (e.g. "red") instead of the hex-codes.
147147
````
148148

149149
````{solution}
150150
```{code-block} python
151151
---
152-
emphasize-lines: 12, 15, 20-21, 26
152+
emphasize-lines: 9, 12, 17-18, 23
153153
---
154-
# this line tells Jupyter to display matplotlib figures in the notebook
155-
%matplotlib inline
156-
157154
import matplotlib.pyplot as plt
158155
159156
# this is dataset 1 from
@@ -165,13 +162,13 @@ data_y = [8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68]
165162
data2_y = [9.14, 8.14, 8.74, 8.77, 9.26, 8.10, 6.13, 3.10, 9.13, 7.26, 4.74]
166163
167164
# here we multiply all elements of data2_y by 2.0
168-
data2_y_scaled = [y*2.0 for y in data2_y]
165+
data2_y_scaled = [y * 2.0 for y in data2_y]
169166
170167
fig, ax = plt.subplots()
171168
172-
ax.scatter(x=data_x, y=data_y, c="#E69F00", label='set 1')
173-
ax.scatter(x=data_x, y=data2_y, c="#56B4E9", label='set 2')
174-
ax.scatter(x=data_x, y=data2_y_scaled, c="#009E73", label='set 2 (scaled)')
169+
ax.scatter(x=data_x, y=data_y, c="#E69F00", label="set 1")
170+
ax.scatter(x=data_x, y=data2_y, c="#56B4E9", label="set 2")
171+
ax.scatter(x=data_x, y=data2_y_scaled, c="#009E73", label="set 2 (scaled)")
175172
176173
ax.set_xlabel("we should label the x axis")
177174
ax.set_ylabel("we should label the y axis")
@@ -187,7 +184,7 @@ ax.legend()
187184
This qualitative color palette is opimized for all color-vision
188185
deficiencies, see <https://clauswilke.com/dataviz/color-pitfalls.html> and
189186
[Okabe, M., and K. Ito. 2008. "Color Universal Design (CUD):
190-
How to Make Figures and Presentations That Are Friendly to Colorblind People."](http://jfly.iam.u-tokyo.ac.jp/color/).
187+
How to Make Figures and Presentations That Are Friendly to Colorblind People"](http://jfly.iam.u-tokyo.ac.jp/color/).
191188
```
192189

193190
---
13.1 KB
Loading
9.36 KB
Loading

0 commit comments

Comments
 (0)