Re: "Sticky" options when using Plot[] -- bug or feature?

*To*: mathgroup at smc.vnet.net*Subject*: [mg99451] Re: [mg99403] "Sticky" options when using Plot[] -- bug or feature?*From*: Bob Hanlon <hanlonr at cox.net>*Date*: Wed, 6 May 2009 05:22:04 -0400 (EDT)*Reply-to*: hanlonr at cox.net

SetOptions is permanent for the session or at least until the next SetOptions. If you want option settings to be temporary for a specific plot, then set the options within that Plot statement. Alternatively, if you want to use SetOptions and then subsequently restore every option to its original desault value without having to respecify each option that you changed, just remember them all. defaultPlotOpts = Options[Plot]; p1 = Plot[Cos[x], {x, -Pi, Pi}] << PlotLegends` bs = {FontFamily -> "Arial", FontSize -> 14, FontWeight -> Bold}; SetOptions[Plot, Frame -> True, FrameStyle -> AbsoluteThickness[2], GridLines -> Automatic, PlotStyle -> {{Red, AbsoluteThickness[2]}, {Black, AbsoluteThickness[2]}, {Blue, AbsoluteThickness[2]}, {Darker@Green, AbsoluteThickness[2]}}, BaseStyle -> bs]; Note that the Options set within the Plot statement below override the defaults (which are now the original defaults as modified by your SetOptions). Plot[{Sin[x], Cos[x], Tan[x]}, {x, 0, 1}, PlotStyle -> {Directive[Blue, Thick], Directive[Thick, Red, DotDashed], Directive[Thick, Green, Dotted]}, Background -> LightOrange, PlotLegend -> {"sin x", "cos x", "tan x"}, LegendPosition -> {-.65, -.15}, LegendOrientation -> Vertical, LegendBackground -> LightPurple, LegendShadow -> {.02, -.02}, LegendSize -> {0.3, 0.35}, FrameLabel -> {"x", "trig functions"}] Restoring all Plot options to the original defaults: SetOptions[Plot, defaultPlotOpts]; p2 = Plot[Cos[x], {x, -Pi, Pi}] The two Cos Plots are identical p1 === p2 True Bob Hanlon ---- Bob F <deepyogurt at gmail.com> wrote: ============= Any idea why the first and last "Plot[Cos[x], {x, -Pi, Pi}]" below come out so much differently? It would appear that some of the options are a bit "sticky" in the sense that they are not reset for the second "Plot[Cos[x], {x, -Pi, Pi}]". Is this a bug or a feature? And make sure that you start with a fresh kernel in case something has already been done for the first Plot[] call ... Plot[Cos[x], {x, -Pi, Pi}] << PlotLegends` bs = {FontFamily -> "Arial", FontSize -> 14, FontWeight -> Bold}; SetOptions[Plot, Frame -> True, FrameStyle -> AbsoluteThickness[2], GridLines -> Automatic, PlotStyle -> {{Red, AbsoluteThickness[2]}, {Black, AbsoluteThickness[2]}, {Blue, AbsoluteThickness[2]}, {Darker@Green, AbsoluteThickness[2]}}, BaseStyle -> bs]; Plot[{Sin[x], Cos[x], Tan[x]}, {x, 0, 1}, PlotStyle -> {Directive[Blue, Thick], Directive[Thick, Red, DotDashed], Directive[Thick, Green, Dotted]}, Background -> LightOrange, PlotLegend -> {"sin x", "cos x", "tan x"}, LegendPosition -> {-.6, 0.1}, LegendOrientation -> Vertical, LegendBackground -> LightPurple, LegendShadow -> {.02, -.02}, LegendSize -> {0.3, 0.35}, FrameLabel -> {"x", "trig functions"}] Plot[Cos[x], {x, -Pi, Pi}] Please let me know if you find the same problem. I tried this on a Mac OS X 10.5.6 system with version 7.0.1 of Mathematica. Thanks... -Bob