The order of lines in ax.lines

Predict the output · Medium · §6.1 Diagnosing before polishing

The code draws the rainfall of three cities from June to August as three lines, then looks at the lines stored in the Axes, ax.lines. get_label() returns a line's label, and get_linestyle() returns its line style. Predict the three lines of output without running the code.

Code

import matplotlib.pyplot as plt

rain = {"Daegu": [90, 210, 240], "Gwangju": [150, 320, 290], "Incheon": [100, 260, 300]}

fig, ax = plt.subplots()
for city in sorted(rain, reverse=True):
    ax.plot(["Jun", "Jul", "Aug"], rain[city], label=city)

print(len(ax.lines))
print(ax.lines[0].get_label())
ax.lines[-1].set(color="#888888", linestyle="--")
print(ax.lines[-1].get_label(), ax.lines[-1].get_linestyle())

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.