I have a complicated function for StreamPlot to call that includes some error checking and the use of Message. Somehow the messages are not displayed when the function is called from StreamPlot. Here's a toy example:

Define the function & message:

f[x_] := Module[{},
  If[x > 1, Print["print: ", x]; Message[f::msg, x]];

f::msg = "`1` is greater than 1";

Test it by itself:

(* print: 1.2 *)
(* f::msg f:1.2` is greater than 1 *)
(* 1.2 *)

Works as expected, but put it in a StreamPlot and only the Printed messages are shown:

StreamPlot[{f[x], y}, {x, 0, 1.2}, {y, 0, 1}]
(* txt: 1.22403 *)
(* txt: 1.22403 *)
(* ... *)

How can I get those Messages to show?


Plot eats Messages too.

  • $\begingroup$ Oddly, it does not eat one of the messages here. $\endgroup$
    – Michael E2
    Commented Mar 27, 2017 at 19:09

2 Answers 2


You need to reset $Messages.

f[x_] := Module[{}, 
   If[x > 1, Print["print: ", x]; 
    Block[{$Messages = Streams["stdout"]},
     If[! ListQ@$MessageList, $MessageList = {}];
     Message[f::msg, x]]];

$MessageList should be a list, which if is not when f is called. Just what to do about it, whether to Block it too or reset it globally as above, I am not completely sure. It worked both ways with the following plot:

Plot[f[x], {x, 0, 1.01}]
  • $\begingroup$ Thanks! Seems like I will need to replace a lot of calls to Message with something like this. Could this be wrapped into a plug-and-play function with identical syntax to Message? Also, would you consider this a bug to report to WRI? $\endgroup$
    – Chris K
    Commented Mar 27, 2017 at 20:16
  • $\begingroup$ In response to my first question in the previous comment, seems so. Will add as a separate answer later tonight. $\endgroup$
    – Chris K
    Commented Mar 27, 2017 at 21:53

Here's my attempt to wrap up @MichaelE2's trick into a plug-and-play replacement for Message:

Msg[msgs__] := Block[{$Messages = Streams["stdout"]},
  If[!ListQ@$MessageList, $MessageList = {}];
SetAttributes[Msg, HoldAll];

This seems to work except it usually overrules General::stop in Plot and StreamPlot, which I can live with.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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