Understand the idea
An axis scale controls the spacing of values; limits control the visible range. Neither changes the underlying observations.
A small example
On a log axis, 1→10 and 10→100 take equal space: each is a tenfold increase.
Follow the code
Apply the idea to the supplied table. Read from top to bottom; the final line displays the result.
import matplotlib.pyplot as plt
import seaborn as sns
fig, ax = plt.subplots(figsize=(6, 4))
sns.scatterplot(data=df, x="requests", y="response_ms", ax=ax)
ax.set_xscale("log")
ax.set_ylim(bottom=0)
ax.tick_params(axis="x", labelrotation=30)
ax.set(title="Service load test", xlabel="Requests", ylabel="Response time (ms)")
fig.tight_layout()
plt.show()What each part does
ax.set_xscale("log")- logarithmic x axis
ax.set_ylim(bottom=0)- y begins at zero
Other choices for later exercises
ax.tick_params(axis="x", labelrotation=30)- rotate x labels
Your inputs
The editable setup on the right creates df. Run executes the setup and your work from top to bottom.
| requests | response_ms |
|---|---|
| 10 | 35 |
| 30 | 37 |
| 100 | 42 |
| 300 | 60 |
| 1000 | 110 |
| 3000 | 240 |
Your task · Follow
- The supplied df spans several orders of magnitude in request count.
- Plot requests against response_ms on a logarithmic x-axis and a linear y-axis starting at zero.
- Rotate x tick labels by 30 degrees.
- Use: set_xscale().
- Chart: title "Service load test"; x "Requests"; y "Response time (ms)".
Hint
Choose the observations first, then map the requested measurements to the chart.
Reveal solution
One way to do it. Keep any supplied setup in the editor and use this in the Your work section.
import matplotlib.pyplot as plt
import seaborn as sns
fig, ax = plt.subplots(figsize=(6, 4))
sns.scatterplot(data=df, x="requests", y="response_ms", ax=ax)
ax.set_xscale("log")
ax.set_ylim(bottom=0)
ax.tick_params(axis="x", labelrotation=30)
ax.set(title="Service load test", xlabel="Requests", ylabel="Response time (ms)")
fig.tight_layout()
plt.show()