9 c] Explain with neat diagram Anatomy of a Matplotlib Figure and Plotting data points with multiple markers.
Matplotlib gives us the ability not only to display data, but also design the whole Figure around it by adjusting the Grid, X and Y ticks, tick labels, and the Legend. This implies that we can modify every single bit of a plot, starting from the Title and Legend, right down to the major and minor ticks on the spines:
Taking a deeper look into the anatomy of a Figure object, we can observe the
following components:
- Spines: Lines connecting the axis tick marks
- Title: Text label of the whole Figure object
- Legend: Describes the content of the plot
- Grid: Vertical and horizontal lines used as an extension of the tick marks
- X/Y axis label: Text labels for the X and Y axes below the spines
- Minor tick: Small value indicators between the major tick marks
- Minor tick label: Text label that will be displayed at the minor ticks
- Major tick: Major value indicators on the spines
- Major tick label: Text label that will be displayed at the major ticks
- Line: Plotting type that connects data points with a line
- Markers: Plotting type that plots every data point with a defined marker
Format Strings
Before we actually plot something, let’s quickly discuss format strings. They are a neat way to specify colors, marker types, and line styles. A format string is specified as [color][marker][line], where each item is optional. If the color argument is the only argument of the format string, you can use matplotlib.colors. Matplotlib recognizes the following formats, among others:
- RGB or RGBA float tuples (for example, (0.2, 0.4, 0.3) or (0.2, 0.4, 0.3, 0.5))
- RGB or RGBA hex strings (for example, ‘#0F0F0F’ or ‘#0F0F0F0F’)
The following table is an example of how a color can be represented in one particular format:
All the available line styles are illustrated in the following diagram. In general, solid lines should be used. We recommend restricting the use of dashed and dotted lines to either visualize some bounds/targets/goals or to depict uncertainty, for example, in a forecast: