Stack Overflow
numpy
Answer by John Zwinck
We can use masked arrays for this:
log_x = np.ma.log(x).filled(0)
matplotlib
Answer by Joe Kington
Normally, when you call
plt.figure()
, it:
- Creates the figure object that’s returned
- Creates a
FigureManager
for that figure using the appropriate backend- The figure manager creates a
FigureCanvas
, gui window (as needed), andNavigationToolbar2
(zoom buttons, etc)- The figure manager instance is then added to
_pylab_helpers.Gcf
’s list of figures.It’s this last step that we want to bypass.