Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was using Needs["PlotLegends"] By chance I removed ShowLegend by Remove[ShowLegend] How do I get back this function without restarting the kernel? Applying Needs["PlotLegends"] again seems not to help.

share|improve this question
I edited the title, I hope you don't mind – ssch Dec 14 '12 at 12:40
Note that reloading a package in such a case is a necessary but often not sufficient measure in such situations. In particular, if there are symbols defined in Mathematica session (in other packages that use that one or otherwise) which refer to the symbol you removed, you have to reload those packages / definitions as well. The problem is made worse by the fact that there are no warnings, neither when you remove the symbol, nor later when you call those functions. Their definitions simply become invalid. And the re-introduction of the symbol into Mathematica session does not help it. – Leonid Shifrin Dec 14 '12 at 12:56
up vote 10 down vote accepted

Needs is meant to only load the package if it is not already loaded.

In this case, since you removed one symbol from that context, Needs did not know this, it just looked and saw that the context is there and said, Ok, no need to reload it. It does not look to see that you have removed one symbol from that context.

As a work around, use Get since Get will reload the whole context each time even if it is already loaded before.

Cases[Contexts[], "PlotLegends`"]
(*   {}  *)

Cases[Contexts[], "PlotLegends`"]
(*  {"PlotLegends`"}  *)

Cases[Names["PlotLegends`*"], "ShowLegend"]
(* {"ShowLegend"} *)

Cases[Names["PlotLegends`*"], "ShowLegend"]
(*  {} *)

Cases[Names["PlotLegends`*"], "ShowLegend"]
(*  {}  This shows package was not reloaded, hence symbol still missing*)   

Cases[Names["PlotLegends`*"], "ShowLegend"]
(* {"ShowLegend"}  OK *)

Hence use Get

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.