MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: change PlotStyle in Graphics object after the fact?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47273] RE: [mg47253] change PlotStyle in Graphics object after the fact?
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Fri, 2 Apr 2004 03:30:15 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: jflanigan at netzero.net [mailto:jflanigan at netzero.net]
To: mathgroup at smc.vnet.net
>Sent: Thursday, April 01, 2004 7:04 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg47273] [mg47253] change PlotStyle in Graphics object after the fact?
>
>
>Hi,
>
>I have a number of graphics objects created like
>
>p1=Plot[f[x],{x,-1,1}]
>p2=Plot[g[x], {x,-1,2}]
>
>and I was wondering if I can change the PlotStyle on p1 and p2 by
>doing something like
>
>p2/.PlotStyle->{new plot style options}
>
>Any ideas?
>
>Thanks in advance.
>
>PS. Please reply to this group. Spammers have destroyed this e-mail
>address.
>

The problem of replacing is to locate the original options in the graphics
object. If you know them (and perhaps if they happen to be different) you
can simply replace them, e.g.

In[1]:=
g0 = Plot[{BesselJ[2, s], BesselJ[3, s]}, {s, 0, 10}, 
    PlotStyle -> {Hue[0], {Dashing[{.02}], Hue[1/3, 1, .5]}}]


In[5]:=
Show[g0 /. {{Hue[0], graphicsElements__} :> {Thickness[.01], Hue[0], 
          graphicsElements}, {Dashing[{.02}], Hue[1/3, 1, .5], 
          graphicsElements__} :> {Thickness[.01], Hue[2/3], 
          graphicsElements}}]


If your know the structure of your graphics object, you may operate
surgically:

In[6]:=
ReplacePart[g0,
    {{Hue[2/3], Dashing[{.005, .02}], g0[[1, 1, -1]]},
     {Hue[0], g0[[1, 2, -1]]}},
    {{1, 1}, {1, 2}}, {{1}, {2}}] // Show


If you however do that regularly, then prepare your graphics first with
markers:

In[7]:=
g1 = Plot[{BesselJ[2, s], BesselJ[3, s]}, {s, 0, 10}, 
    PlotStyle -> {style[1], style[2]}, DisplayFunction -> Identity]

and then insert the directives at Show:

In[8]:=
Show[g1 /. {style[1] -> Hue[0, .7, 1], 
      style[2] -> Sequence[Dashing[{.02}], Hue[1/3, 1, .5]]}, 
  DisplayFunction -> $DisplayFunction]

or like this

In[10]:=
Block[{style},
  style[1] = Hue[0, .7, 1]; 
  style[2] = Sequence[Dashing[{.02}], Hue[1/3, 1, .5]]; 
  Show[g1, DisplayFunction -> $DisplayFunction]]



or even, if you like or for fun, do that:

In[25]:=
Block[{style, $DisplayFunction}, 
  do3 = Plot[{BesselJ[2, s], BesselJ[3, s]}, {s, 0, 10}, 
        PlotStyle -> {style[1], style[2]}];]

In[29]:=
style[1] = Hue[2/3]; style[2] = Sequence[Dashing[{.02}], Hue[0]]; do3

In[33]:=
style[1] = Hue[1/4]; style[2] = Hue[3/4]; do3

do3 displays itself. That miracle is resolved by

In[34]:= OwnValues[do3] // InputForm



--
Hartmut Wolf


  • Prev by Date: Re: sort list
  • Next by Date: Re: Defining anti-symmetric operation. New ideas requested.
  • Previous by thread: RE: change PlotStyle in Graphics object after the fact?
  • Next by thread: RE: RE: change PlotStyle in Graphics object after the fact?