Re: weird behavior when plotting multiple functions in 6.0
- To: mathgroup at smc.vnet.net
- Subject: [mg76267] Re: weird behavior when plotting multiple functions in 6.0
- From: Roman <rschmied at gmail.com>
- Date: Fri, 18 May 2007 06:30:15 -0400 (EDT)
- References: <f2btov$iga$1@smc.vnet.net>
Hello all, Here's my attempt at a workaround, defining a plotting function which will color things properly. I've tried to list all relevant elements of Options[Plot] in the rules for the mock Plot[] call, and removed those like Filling which give warnings, but have not tested this very much yet. MultiPlot[f_, R_, opts:OptionsPattern[]] := Module[{x, X, Y, Z}, (* extract the name of the abscissa variable *) x = {R}[[1, 1]]; (* mock plotting, evaluating the function f[x] with adaptive algorithm *) X = Reap[Plot[Sow[{x, f}][[2]], R, Evaluate[FilterRules[{opts}, {Evaluated -> Automatic, EvaluationMonitor -> None, Exclusions -> Automatic, MaxRecursion -> Automatic, Method -> Automatic, PerformanceGoal :> $PerformanceGoal, RegionFunction -> (True &), WorkingPrecision -> MachinePrecision}]]]][[2, 1]]; (* drop the attempted analytical evaluations and sort *) Y = Sort[Cases[X, {_Real, _}]]; (* extract abscissa values *) Z = Transpose[Y][[1]]; (* replot with proper coloring *) ListLinePlot[Transpose[{Z, #}]&/@Transpose[Transpose[Y][[2]]], Evaluate[FilterRules[{opts}, Options[ListLinePlot]]]]] SetAttributes[MultiPlot, HoldAll] You can see the difference here: f[x_?NumericQ] := {Sin[x], Cos[x], Tan[x]} Plot[f[y], {y, 0, 2*Pi}, PlotRange -> {-2, 2}, Filling -> {1 -> 0, 2 - > -2, 3 -> 1}] MultiPlot[f[y], {y, 0, 2*Pi}, PlotRange -> {-2, 2}, Filling -> {1 -> 0, 2 -> -2, 3 -> 1}] Any opinions on the above code? Cheers! Roman. On May 15, 11:16 am, Roman <rschm... at gmail.com> wrote: > Hello all: > > When I plot > Plot[{Sin[x], Cos[x]}, {x, 0, 4*Pi}] > I get two curves: one blue, one red. > > But when I do > f[x_] = {Sin[x], Cos[x]}; > Plot[f[x], {x, 0, 4*Pi}] > both curves are blue. It is as if at some level Mathematica does not > understand that I'm actually plotting two curves at a time, and uses > the first color specification (blue) for both curves. > > This is particularly annoying when you want to play with plot styles, > for example filling instructions, like > Filling -> {1 -> -1, 2 -> 1} > which works in the first example but not in the second one. > > Has anyone figured out a workaround for this one? > > Thanks! > Roman.
- Follow-Ups:
- Re: Re: weird behavior when plotting multiple functions in 6.0
- From: "Lev Bishop" <lev.bishop@gmail.com>
- Re: Re: weird behavior when plotting multiple functions in 6.0