Python 3 pyplot.hold is deprecated

Python 3 pyplot.hold is deprecated … here is a solution to the problem.

Python 3 pyplot.hold is deprecated

I want to

use pyplot.hold(True) because I want to plot contour plots on scatterplots. When I use the code below, it has the warning that pyplot.hold is deprecated. Are there other options in Python 3, or am I just ignoring the warning? Thank you so much.

plt.scatter(X[:, 0], X[:, 1], s=150, c='b', 
marker='x', linewidths=1)
plt.hold(True)
plt.contour(X1, X2, Z, np.power(10,(np.arange(-20, 
0.1, 3)). T))
plt.hold(False)

Solution

Matplotlib itself does not remove anything from the drawing. Therefore, the concept of keeping is not necessary in matplotlib and will be removed.

So your code should look like

this

plt.scatter(..)
plt.contour(..)

May be followed by plt.savefig(..) or plt.show().

Related Problems and Solutions