Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3 pyplot.hold is deprecated

I would like to use the pyplot.hold(True) since I want to draw a contour plot on a scatter plot. When I use the below code, it has the warning that pyplot.hold is deprecated. Is there any other option in Python 3 or I just ignore the warning? Thank you very 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)
like image 524
Emma Zhang Avatar asked Dec 22 '25 08:12

Emma Zhang


1 Answers

Matplotlib does not erase any content from a figure by itself. The concept of hold is hence not necessary in matplotlib and will be removed.

Your code should therefore look like

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

Possibly followed by plt.savefig(..) or plt.show().

like image 82
ImportanceOfBeingErnest Avatar answered Dec 23 '25 22:12

ImportanceOfBeingErnest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!