Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
979 changes: 979 additions & 0 deletions AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb

Large diffs are not rendered by default.

846 changes: 0 additions & 846 deletions AnatomyOfMatplotlib-Part1-pyplot.ipynb

This file was deleted.

3 changes: 0 additions & 3 deletions exercises/1.1-limits.py

This file was deleted.

11 changes: 11 additions & 0 deletions exercises/1.1-subplots_and_basic_plotting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import numpy as np
import matplotlib.pyplot as plt

# Try to reproduce the figure shown in images/exercise_1-1.png

# Our data...
x = np.linspace(0, 10, 100)
y1, y2, y3 = np.cos(x), np.cos(x + 1), np.cos(x + 2)
names = ['Signal 1', 'Signal 2', 'Signal 3']

# Can you figure out what to do next to plot x vs y1, y2, and y3 on one figure?
15 changes: 15 additions & 0 deletions exercises/1.2-legends_and_scaling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import numpy as np
import matplotlib.pyplot as plt

# Try to reproduce the figure shown in images/exercise_1-2.png
# Here's the data and colors used.

t = np.linspace(0, 2 * np.pi, 150)
x1, y1 = np.cos(t), np.sin(t)
x2, y2 = 2 * x1, 2 * y1

colors = ['darkred', 'darkgreen']

# Try to plot the two circles, scale the axes as shown and add a legend
# Hint: it's easiest to combine `ax.axis(...)` and `ax.margins(...)` to scale
# the axes
23 changes: 0 additions & 23 deletions exercises/1.2-spines.py

This file was deleted.

9 changes: 9 additions & 0 deletions exercises/1.3-spines_ticks_and_subplot_spacing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import matplotlib.pyplot as plt
import numpy as np

# Try to reproduce the figure shown in images/exercise_1.3.png
# This one is a bit trickier!

# Here's the data...
data = [('dogs', 4, 4), ('frogs', -3, 1), ('cats', 1, 5), ('goldfish', -2, 2)]
animals, friendliness, popularity = zip(*data)
Binary file added images/exercise_1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/exercise_1-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/exercise_1.3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/figure_axes_axis_labeled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions solutions/1.1-limits.py

This file was deleted.

14 changes: 14 additions & 0 deletions solutions/1.1-subplots_and_basic_plotting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 10, 100)
y1, y2, y3 = np.cos(x), np.cos(x + 1), np.cos(x + 2)
names = ['Signal 1', 'Signal 2', 'Signal 3']

fig, axes = plt.subplots(nrows=3)

for ax, y, name in zip(axes, [y1, y2, y3], names):
ax.plot(x, y, color='black')
ax.set(xticks=[], yticks=[], title=name)

plt.show()
18 changes: 18 additions & 0 deletions solutions/1.2-legends_and_scaling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0, 2 * np.pi, 150)
x1, y1 = np.cos(t), np.sin(t)
x2, y2 = 2 * x1, 2 * y1

colors = ['darkred', 'darkgreen']

fig, ax = plt.subplots()
ax.plot(x1, y1, color=colors[0], label='Inner', linewidth=3)
ax.plot(x2, y2, color=colors[1], label='Outer', linewidth=3)
ax.legend()

ax.axis('equal')
ax.margins(0.05)

plt.show()
12 changes: 0 additions & 12 deletions solutions/1.2-spines.py

This file was deleted.

25 changes: 25 additions & 0 deletions solutions/1.3-spines_ticks_and_subplot_spacing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import matplotlib.pyplot as plt
import numpy as np

data = [('dogs', 4, 4), ('frogs', -3, 1), ('cats', 1, 5), ('goldfish', -2, 2)]
animals, friendliness, popularity = zip(*data)


def plot_and_setup_spines(ax, animals, y, ylabel):
x = np.arange(len(animals))
ax.bar(x, y, align='center', color='gray')
ax.set(xticks=x, xticklabels=animals, ylabel=ylabel)

ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.spines['bottom'].set_position(('data', 0))
ax.tick_params(axis='x', direction='inout', length=8)
ax.margins(0.05)

fig, axes = plt.subplots(nrows=2)
fig.subplots_adjust(hspace=0.0)

plot_and_setup_spines(axes[0], animals, friendliness, 'Friendliness')
plot_and_setup_spines(axes[1], animals, popularity, 'Popularity')

plt.show()