0

I imported matplotlib.pyplot as plt, then mistakenly defined a variable with the the function matplotlib.pyplot.xticks function name (i.e. plt.xticks = ... instead of plt.xticks(...)) in a Jupyter notebook. Then I tried to undo the definition with del plt.xticks and it removed the variable, but also the function. I tried reimporting matplotlib, but still plt.xticks is not there:

plt.xticks

AttributeError: module 'matplotlib.pyplot' has no attribute 'xticks'

In other notebooks the command works, even after reimporting the library. In this specific notebook I can get around the problem by import matplotlib. Is there another way around?

GWSurfer
  • 31
  • 9
  • `import matplotlib.pyplot as plt` didn't work? That's just a fancy assignment statement, and it should overwrite whatever value `plt` is bound to with the module. – chepner Nov 12 '19 at 14:57
  • If you import something again that's already been imported, [nothing happens](https://stackoverflow.com/a/19077396/4739755). You can use [`importlib.reload`](https://docs.python.org/3/library/importlib.html#importlib.reload) to force a re-assignment/re-read of the module contents however. Edit: To clarify, this _will not_ fix the OP's problem however. Re-definitions of names will remain. – b_c Nov 12 '19 at 15:01

1 Answers1

1

I did the same thing once, restarting the kernel did the trick.

Louis Hulot
  • 357
  • 2
  • 13