Data Visualization with matplotlib pyplot
What this domain tests
The exam checks that you can choose the correct chart type, write the plotting calls, label the axes and title, and read meaning from a finished graph.
Chart types and when to use them
plt.plot(x, y)draws a line, best for a trend over time or an ordered sequence.plt.bar(x, height)compares values across categories.plt.hist(data, bins=n)shows the frequency distribution of continuous data, grouping values into intervals.plt.scatter(x, y)shows the relationship between two numeric variables and hints at correlation.
Labels, titles and display
Call plt.xlabel(), plt.ylabel(), plt.title() and, when several series are drawn, plt.legend() after giving each plot() a label=. plt.show() displays the figure; plt.savefig('name.png') stores it. Styling options include color, marker, linestyle and linewidth. Several plot() calls before one show() overlay lines on the same axes.
Worked example
A class has marks in five subjects. To compare subject averages, draw a bar chart, because the subjects are categories. To see how individual marks are spread, draw a histogram, because the marks are continuous and repetition counts matter. Drawing a line for the subject averages would wrongly suggest a continuous progression between subjects. The reasoning is the data type: categories call for bars, distributions call for histograms, paired numeric variables call for scatter, and ordered time points call for lines.
Reading a graph
An upward line means an increasing trend; a scatter that rises from left to right means positive correlation; a histogram with a long right tail is positively skewed; a single tall bar in a histogram marks the modal class interval.
Traps that cost marks
Omitting axis labels or the title; calling legend() without label=; using plot() for a correlation study; forgetting show(); choosing a pie or line chart where a histogram is required; describing the chart instead of interpreting it.