A DOTTED GRID IN MATPLOTLIB
Listing 5.9 displays the content of plotdottedgrid1.py that illustrates how to plot a “dotted” grid pattern.
LISTING 5.9: plotdottedgrid1.py
import numpy as np import pylab from itertools import product import matplotlib.pyplot as plt fig = pylab.figure() ax = fig.add_subplot(1,1,1) ax.grid(which='major', axis='both', linestyle='--') [line.set_zorder(3) for line in ax.lines] fig.show() # to update plt.gca().xaxis.grid(True) plt.show()
Listing 5.9 is similar to the code in Listing 5.8 in that both of them plot a grid-like pattern; however, the former renders a “dotted” grid pattern whereas the latter renders a “dotted” grid pattern by specifying the value '--' for the linestyle parameter.
The next portion of Listing 5.9 invokes the set_zorder() method, that controls which items are displayed on top of other items, such as dots on top of lines, or vice versa. The final portion...