MathGroup Archive 2003

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

Search the Archive

RE: Mesh in ListDensityPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42290] RE: [mg42265] Mesh in ListDensityPlot
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Fri, 27 Jun 2003 06:31:19 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Walden, CJ (Chris) [mailto:C.J.Walden at rl.ac.uk]
To: mathgroup at smc.vnet.net
>Sent: Thursday, June 26, 2003 11:36 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg42290] [mg42265] Mesh in ListDensityPlot
>
>
>Hi,
>
>I'm using ListDensityPlot to display a 2880 by 200 matrix of 
>real values.
>If I set Mesh->True the result is completely dominated by 
>black mesh lines.
>Does anyone know an easy way of displaying a subset of mesh lines?
>
>Thanks,
>
>Chris Walden
>
>-- 
>-----------------------------------------------
>Dr C.J. Walden	[C.J.Walden at rl.ac.uk]
>Radio Communications Research Unit 
>CCLRC Rutherford Appleton Laboratory
>Chilton, Didcot, OX11 0QX, UK
>Tel:+44-(0)1235-445601	Fax:+44-(0)1235-446140
>-----------------------------------------------
>

Chris,

certainly there is the alternative to just overlay a mesh, made up by
yourself from Graphics primitves over your ListDensityPlot (without mesh).

I will show here, an alternative, namely: how to thin out the mesh from the
DensityGraphics:


Let's define some data:

In[1]:= \[Delta]2 = 40/2880 // N;
        \[Delta]1 = 20/200 // N;

In[3]:=
data = Table[Sin[x]/Cos[x^2 + y^2],
             {x, -10 + \[Delta]1/2, 10 - \[Delta]1/2, \[Delta]1},
             {y, -20 + \[Delta]2/2, 20 - \[Delta]2/2, \[Delta]2}]; 

In[4]:=
gd = ListDensityPlot[data, Mesh -> True, MeshRange -> {{-20, 20}, {-10,
10}}, 
    AspectRatio -> Automatic, ImageSize -> 800, MeshStyle -> {Hue[1/6]}]

Out[4]= \[SkeletonIndicator]DensityGraphics\[SkeletonIndicator]

This density graphics is unusable (all yellow from the mesh).


We convert the DensityGraphics to a Graphics:

In[5]:= g = Graphics[gd]
Out[5]= \[SkeletonIndicator]Graphics\[SkeletonIndicator]
 

>From that we extract the mesh lines and it's graphics directives:

In[6]:= oldmesh = Extract[g, pos = Position[g, {___, Line[_] ..}]];
In[7]:= directives = DeleteCases[oldmesh, Line[_], {2}]
Out[7]= {{Hue[1/6], AbsoluteThickness[0.25`], Dashing[{}]}}
In[8]:= pos
Out[8]= {{1, 2}}
In[9]:= lines = Cases[oldmesh, Line[_], {2}];
 

This are the dimensions of the data:

In[10]:= dd = Dimensions[data]
Out[10]= {200, 2880}

In[11]:= FactorInteger[dd]
Out[11]= {{{2, 3}, {5, 2}}, {{2, 6}, {3, 2}, {5, 1}}}

We search for a pleasant factor for thinning out, and choose

In[12]:= s = {20, 80};


In[13]:= ii = Transpose[{{-1, 1}, {-1, 1}*(dd + 1), s}]
Out[13]= {{-1, -201, 20}, {1, 2881, 80}}
In[14]:= pp = ReplacePart[ii, ii, {{1, 1}, {1, 2}}, {{1, 2}, {1, 1}}]
Out[14]= {{-201, -1, 20}, {1, 2881, 80}}

These are the sequence specifications to take out the thinned mesh. Note the
expression dd+1 (there is one meshline more for each dimension).

In[15]:= newlines = Take[lines, #] & /@ pp;

In[16]:= newmesh = Join @@ Join[directives, newlines];

In the Graphics object, we replace the old mesh by the new one:

In[17]:= gnew = ReplacePart[g, newmesh, pos]
Out[17]= \[SkeletonIndicator]Graphics\[SkeletonIndicator]


All that needs, is to display it:

In[18]:= Show[gnew, Background -> Hue[.8, .2, .8]]


By the way: don't think the Ranges for the mesh were false (by a tiny
amount), to the contrary! They are just right here (but often false
otherwise!). Why?



Well, because it is so easy, here the other method:

In[23]:=
gd0 = ListDensityPlot[data, Mesh -> False, 
    MeshRange -> {{-20, 20}, {-10, 10}}, AspectRatio -> Automatic, 
    ImageSize -> 800]


In[24]:=
Show[gd0, 
  Graphics[ {Hue[0], Table[Line[{{-20, i}, {20, i}}], {i, -10, 10, 2}], 
      Table[Line[{{j, -10}, {j, 10}}], {j, -20, 20, 2}]}]]

(we simply don't care for the raster, if it is small enough)



--
Hartmut Wolf


  • Prev by Date: Re: Re: format Text in graphics
  • Next by Date: Re: Re: Re: format Text in graphics
  • Previous by thread: RE: Mesh in ListDensityPlot
  • Next by thread: minimum