|
13 | 13 | """ |
14 | 14 | import matplotlib.pyplot as plt |
15 | 15 |
|
16 | | -names = ['group_a', 'group_b', 'group_c'] |
17 | | -values = [1, 10, 100] |
| 16 | +data = {'apples': 10, 'oranges': 15, 'lemons': 5, 'limes': 20} |
| 17 | +names = list(data.keys()) |
| 18 | +values = list(data.values()) |
18 | 19 |
|
19 | | -fig, axs = plt.subplots(1, 3, figsize=(9, 3)) |
| 20 | +fig, axs = plt.subplots(1, 3, figsize=(9, 3), sharey=True) |
20 | 21 | axs[0].bar(names, values) |
21 | 22 | axs[1].scatter(names, values) |
22 | 23 | axs[2].plot(names, values) |
23 | 24 | fig.suptitle('Categorical Plotting') |
24 | 25 |
|
| 26 | + |
| 27 | +############################################################################### |
| 28 | +# This works on both axes: |
| 29 | + |
| 30 | +cat = ["bored", "happy", "bored", "bored", "happy", "bored"] |
| 31 | +dog = ["happy", "happy", "happy", "happy", "bored", "bored"] |
| 32 | +activity = ["combing", "drinking", "feeding", "napping", "playing", "washing"] |
| 33 | + |
| 34 | +fig, ax = plt.subplots() |
| 35 | +ax.plot(activity, dog, label="dog") |
| 36 | +ax.plot(activity, cat, label="cat") |
| 37 | +ax.legend() |
| 38 | + |
25 | 39 | plt.show() |
0 commit comments