Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

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

Search the Archive

RE: filled plot on part of x-interval

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44622] RE: [mg44599] filled plot on part of x-interval
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Tue, 18 Nov 2003 06:41:52 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Murray Eisenberg [mailto:murray at math.umass.edu]
To: mathgroup at smc.vnet.net
>Sent: Monday, November 17, 2003 9:39 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg44622] [mg44599] filled plot on part of x-interval
>
>
>How do I use a FilledPlot that fills the region under the 
>graph of f[x] 
>only, say, for x from 2 to 10 but still graphs the function 
>itself from 
>0 to 10?
>
>-- 
>Murray Eisenberg                     murray at math.umass.edu
>Mathematics & Statistics Dept.
>Lederle Graduate Research Tower      phone 413 549-1020 (H)
>University of Massachusetts                413 545-2859 (W)
>710 North Pleasant Street            fax   413 545-1801
>Amherst, MA 01003-9305
>

A simple trick would be:

In[1]:= << Graphics`FilledPlot`

In[3]:= f[t_] := (t/7.5)^2 + Sin[t] 

In[4]:= g[t_] := f[t] /; t < 2 || t > 9
In[5]:= g[t_] := 0  /; 2 <= t <= 9

In[6]:= FilledPlot[{f[t], g[t]}, {t, 0, 10}]

The result is not quite perfect, as below and above the shaded region, the
function is plotted twice (at different sampling), and vertical lines are
visible at the borders of the shaded region.



In[7]:= filled = FilledPlot[f[t], {t, 2, 9}, Fills -> {Hue[2/3, .5, 1]}, 
    DisplayFunction -> Identity]
In[8]:=
Plot[f[t], {t, 0, 10}, Prolog -> filled[[1, 2, 1, 1]], 
  PlotStyle -> {GrayLevel[0]}, DisplayFunction -> $DisplayFunction]

Here only the polygon for the shading is retained from filled, but again at
different sampling (such you may see some small open gaps, or the line
blurred over). Furthermore, the abscissa got partially hidden.


In[9]:= pl = Plot[f[t], {t, 0, 10}, DisplayFunction -> Identity]
In[10]:=
Show[pl, Graphics[filled[[1, 2, 1, 1]]], pl, 
  DisplayFunction -> $DisplayFunction, AxesFront -> True]

This makes the axis visible in full, but shares the remaining defects.


With simple means, this was most satisfying to me:

In[11]:= plow = Plot[f[t], {t, 0, 2}, DisplayFunction -> Identity]
In[12]:= plhi = Plot[f[t], {t, 9, 10}, DisplayFunction -> Identity]
In[13]:=
Show[plow, filled, plhi, DisplayFunction -> $DisplayFunction, 
  AxesFront -> True]



If you don't mind switching off an error message, you may do

In[20]:= g1[t_] := f[t] /; t < 2 || t > 9
In[21]:= g2[t_] := f[t]  /; 2 <= t <= 9
In[22]:=
Off[Plot::"plnr"]
In[23]:=
FilledPlot[{g1[t], g2[t]}, {t, 0, 10}, 
  Fills -> {{{2, Axis}, Hue[1/3, .5, 1]}}]



You may seperate concerns a bit:

In[31]:= \[Theta]1[t_, {min_, max_}] := 1 /; t < min || t > max
In[32]:= \[Theta]2[t_, {min_, max_}] := 1 /; min <= t <= max
In[33]:= \[Theta][t_, {min_, max_}] := Through[{\[Theta]1, \[Theta]2}[t,
{min, max}]]

(a strange "partition of unity")

In[34]:= Off[Plot::"plnr"]

In[35]:=
FilledPlot[f[t]*\[Theta][t, {2, 9}], {t, 0, 10}, 
  Fills -> {{{2, Axis}, Hue[1/3, .5, 1]}}]


If you want to have shading between several curves, just do e.g.

In[36]:=
FilledPlot[Append[Cos[t] \[Theta][t, {2, 9}], Sin[t]], {t, 0, 10}, 
  Fills -> {{{2, 3}, Hue[1/6, .5, 1]}}]

In[38]:= On[Plot::"plnr"]

--
Hartmut Wolf


  • Prev by Date: Re: Readability confuses mathematica?
  • Next by Date: Re: Just trying to import an image
  • Previous by thread: RE: filled plot on part of x-interval
  • Next by thread: RE: RE: filled plot on part of x-interval