A line drawn from a table sorted by distance, and zooming in
Predict the output · Medium · §9.4 Exploring and checking
The code draws a line chart from a table of distances (km) run over five days, sorted from the shortest distance, and sets the x-axis range to show only days 2 to 4. Predict the two lines of output without running the code.
Code
import pandas as pd
import plotly.express as px
runs = pd.DataFrame({
"day": [1, 2, 3, 4, 5],
"km": [3.0, 5.5, 4.0, 6.5, 2.5],
})
ranked = runs.sort_values("km")
fig = px.line(ranked, x="day", y="km", markers=True)
fig.update_xaxes(range=[2, 4])
print(fig.data[0].x.tolist())
print(len(fig.data[0].y), len(runs))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.