Controlling a line pattern and thickness
When creating figures for black and white documents, we are limited to gray levels. In practice, three levels of gray are usually the most we can reasonably use. However, using different line patterns allows some diversity. In this recipe, we are going to see how to control line pattern and thickness.
How to do it...
As in the case of colors, the line style is controlled by an optional parameter of pyplot.plot()
as shown in the following script:
import numpy as np import matplotlib.pyplot as plt def pdf(X, mu, sigma): a = 1. / (sigma * np.sqrt(2. * np.pi)) b = -1. / (2. * sigma ** 2) return a * np.exp(b * (X - mu) ** 2) X = np.linspace(-6, 6, 1024) plt.plot(X, pdf(X, 0., 1.), color = 'k', linestyle = 'solid') plt.plot(X, pdf(X, 0., .5), color = 'k', linestyle = 'dashed') plt.plot(X, pdf(X, 0., .25), color = 'k', linestyle = 'dashdot') plt.show()
The preceding script will produce the following graph:
How it works...
In this example, we use...