1

I have overwritten plt.figure = <some random text>, and now I cannot use the plt.figure method as normal. How do I reload the .figure method from matplotlib.pyplot again so I can use it?

I tried import matplotlib.pyplot as plt but plt.figure is still equals to the text I defined as by accident.

Usama Abdulrehman
  • 1,041
  • 3
  • 11
  • 21
Nick Gray
  • 11
  • 2
  • Does this answer your question? [How to restore a builtin that I overwrote by accident?](https://stackoverflow.com/questions/17152760/how-to-restore-a-builtin-that-i-overwrote-by-accident) – G. Anderson Jun 10 '20 at 16:03
  • 1
    @G.Anderson no, that technique will not work for an attribute of a non-builtin global. – Karl Knechtel Aug 09 '22 at 07:09

1 Answers1

1

I am a little confused by your question and why you can not just restart and not overwrite that variable. However, importlib can probably help you out:

import numpy as np
import importlib
np.array = 1
print(np.array) # 1
importlib.reload(np)
print(np.array) # <built-in function array>
  • that's brilliant, thanks! certainly a re-load of the terminal also works, but I have other data which takes some time to load and this is helpful as it allows me to re-load a method in a package if somehow i've stuffed it up by overwriting it. – Nick Gray Jun 10 '20 at 16:58