Message Boards Message Boards

2 Replies
0 Total Likes
View groups...
Share this post:

How to make graphics from a package appear when executing Get[package.m]?

Posted 10 years ago

In previous versions of Mathematica I called packages using Get[package.m]. The graphics output produced in the package by functions such as Plot , ListPlot etc. would show in the notebook where the Get command was executed.

This doesn't work in version 9. How can I restore the previous behavior?
The output from Print still displays.

Thanks for your help.

POSTED BY: Mark Simmons
2 Replies
Posted 10 years ago

Thanks for your answer. Print solves my problem. I knew about the changes in outputting graphics, but didn't expect Print to do it.

I hope Print will not be changed too to be a pure function, although this would certainly be very elegant...
Side effects spread all over do provide a very convenient and simple way of debugging or simply monitoring execution and correctness of larger codes which never reach a finished and final state.

POSTED BY: Mark Simmons

Did you jump from version 5 to version 9? I am going to guess that you did. If the explanation below does not help, please attach a notebook that demonstrates the problem.

Since Mathematica 6, graphics have been the actual output of the plotting function. (Before 6, they were placed in the notebook as side effects.) Placing a semicolon after the plotting function prevents the output plot from appearing in the notebook.

The two workarounds are:

a) Wrap the plotting function with Print, which still uses side-effects.

Print[ Plot[Sin[x]/x, {x,-10,10}, PlotRange->All] ];  

b) Save the plots in a list or in variables and output them at the bottom of the package (no semicolon).

plts = {}; 
AppendTo[plts, ListPlot[...]]; 
AppendTo[plts, Plot3D[...] ]; 

If the problem is that you get "--Graphics--" in your notebook instead of the graphic, please see .

POSTED BY: Bruce Miller
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract