Using different backends to display graphs
Matplotlib can produce high-quality graphs targeting many different platforms and display technologies. To achieve this in an efficient and transparent way, Matplotlib developers introduced the notion of a backend. A backend is code that is designed to render Matplotlib graphs in a particular graphing environment. Users of Matplotlib are mostly insulated from the details of the actual rendering, but some devices and operating systems might require the selection of the appropriate backend.
Getting ready
In this example, we will write our code in a script, so you will need to open your text editor.
How to do it…
Enter the following code in your text editor:
import numpy as np import matplotlib matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt f = lambda x: 1/((x-3)**2+.01) + 1/((x-9)**2+.04) - 6 xvalues = np.linspace(2, 10, 300) yvalues = f(xvalues) plt.plot(xvalues, yvalues) plt.xlabel('$x$') plt.ylabel('$f(x)$') plt.title('The "humps" function...