You're reading from Python Data Visualization Cookbook
A barb is a representation of the speed and direction of wind, and is mainly deployed by meteorology scientists. In theory they can be used to visualize any type of two-dimensional vector quantities. They are similar to arrows (quivers), but the difference is that arrows represent vector magnitude by the length of the arrow, while barbs give more information about the vector's magnitude by employing lines or triangles as increments of magnitude.
We will explain what barbs are, how to read them, and how to visualize them using Python and matplotlib. Here's a typical set of barbs:
In the preceding diagram, the triangle, also known as flag, represents the largest increment. A full line or barb, represents a smaller increment; a half line is the smallest increment.
The increments are in the order of 5, 10, and 65 for a half-line, line, and triangle respectively. The values here represent, for meteorologists at least, wind speed in nautical miles per hour (knots).
We ordered the barbs...
Do you want to visualize a series of data measurement (or observations) to show several properties of the data series (such as the median value, the spread of the data, and the distribution of the data) in one plot? And would you want to do that in a way where you can visually compare several similar data series? How would you visualize them? Welcome to the box-and-whisker plot! Probably the best plot type for comparing distributions, if you are talking to people used to information density.
The box-and-whisker plot usage examples range from comparing test scores between schools to comparing process parameters before and after changes (optimization).
What are the elements of box and whisker plots? As we see in the following diagram, we have several important elements that carry information in the box-and-whisker plot. The first component is the box that carries information about the interquartile range going from lower to upper quartile values....
One form of very widely-used visualization of time-based data is a Gantt chart. Named after the mechanical engineer Henry Gantt who invented it in 1910s, it is almost exclusively used to visualize work breakdown structures in project management. This chart is loved by managers for its descriptive value and not so loved by employees, especially when the project deadline is near.
Because it is very common, almost every one can understand and read it, even if it is overloaded with additional (related and unrelated) information.
A basic Gantt chart has a time series on the x axis, and a set of labels that represent tasks or subtasks on the y axis. Task duration is usually visualized either as a line or as a bar chart, extending from the start to end time of a given task.
If subtasks are present, one or many subtasks have a parent task, in which the case total time of a task is aggregated from subtasks in such a way that overlapping and gap time is accounted for. This is useful...
Error bars are useful to display the dispersion of data on a plot. They are relatively simple as a form of visualization; however, they are also a bit problematic because what is shown as an error varies across different sciences and publications. This does not lessen the usefulness of error bars, it just imposes the need to always be careful and explicitly state the nature of the error visualized as an error bar.
To be able to plot an error bar in the raw observed data, we need to compute the mean and the error we want to display.
The error we compute represents the 95 percent confidence interval that the mean we get from our observation is stable, which means our observations are good estimates of the whole population.
matplotlib supports these type of plots via matplotlib.pyplot.errorbar function
.
It offers several capabilities around error bars. They can be vertical (yerr
) or horizontal (xerr
), and symmetrical or asymmetrical.
We already learned how to annotate the plot by adding legends, but sometimes we want more with text. This recipe will explain and demonstrate more features of text manipulation in matplotlib, giving a powerful toolkit for even advanced typesetting needs.
We will not cover LaTeX support in this recipe, as there is a recipe named Rendering text with LaTeX in this chapter.
We start with listing of the most useful set of functions that matplotlib offers. Most of the functions are available via pyplot
module's interface, but we map their origin function here to allow you to explore more if a particular text feature is not covered in this recipe.
Basic text manipulations and their mapping in matplotlib OO API is presented in the following table:
matplotlib.pyplot |
Matplotlib API |
Description |
---|---|---|
|
Adds text to the axes at the location specified by (x, y). Argument |