Course 4.2Lesson 2 of 3
A plot shows the periodic trends at a glance. You plot the first ionisation enthalpy against the atomic number, colour the points by block and label the noble gases. Then you compare the radius across period 3 with the radius down group 1.
This lesson is free to read. Enroll free to keep your place and take the tests.
Try the code and the simulations beside the lesson.
A column of 36 numbers hides its pattern. A plot shows it at once: the ionisation enthalpy climbs across each period and falls sharply at the start of the next. This is the periodicity that the periodic law describes.
matplotlib draws the plot. Two calls do most of the work:
"o-" draws a dot at each element and joins them with a line. Every axis gets a label with its unit; a plot without units is only half an answer.
A scatter plot can give each point its own colour. A dictionary turns the block letter into a colour, and map applies it to the whole column:
Now the s-block troughs, the p-block climbs and the flat d-block are easy to tell apart.
annotate writes text beside a point. A filter picks the points to label, and a loop writes them:
iterrows() gives each row in turn; the _ takes the row number, which is not needed here.
The second trend is the atomic radius. Across period 3, from sodium to chlorine, it falls from pm to pm. Down group 1, from lithium to potassium, it rises from pm to pm. Two lines on one set of axes, each with a label, and plt.legend() names them.
plt.subplots(2, 1) makes a figure with two plots, one above the other. Each is an axes object, and you draw on it with ax.plot, ax.scatter and ax.set_ylabel, the same names as before with ax. in front.
The program draws the ionisation enthalpy of the first 36 elements, coloured by block with the noble gases labelled, and below it the radius across period 3 and down group 1.
"Atomic radius (pm)".map gives NaN for it, and the point is drawn without a proper colour. Every block letter needs a key.df["radius"].notna() before you plot, or the line breaks oddly.plt.show(). In some places the plot is never drawn without it.plt. and ax. calls on a figure with two plots. Draw on the axes you mean: ax1.plot, ax2.plot.plt.plot(x, y, "o-") draws points joined by a line; plt.scatter(x, y, c=colours) gives each point a colour.df["block"].map(colours) turns block letters into colours, for every row.label and plt.legend().Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
df["block"].map(colours) give for a row whose block is "f", if colours has only s, p and d?Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…