Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

RE: Two questions concerning ListDensityPlot ...

  • To: mathgroup at
  • Subject: [mg28507] RE: [mg28497] Two questions concerning ListDensityPlot ...
  • From: "David Park" <djmp at>
  • Date: Tue, 24 Apr 2001 01:48:45 -0400 (EDT)
  • Sender: owner-wri-mathgroup at


Here is a color function for a matrix:

colorfun[mat_] =
   With[{max = Abs[Max[Max[mat], -Min[mat]]]},
      #1 == 0, Hue[0, 0, 1],
      #1 > 0, Hue[0.6, 0.808, 1 - (0.6*#1)/max],
      True, Hue[0.925, 0.808, 1 + (0.6*#1)/max]]] & ;

The following routine generates a random sparse matrix. I made all the
positive entries above the diagonal and all the negative entires below the
diagonal so we can check that we are orienting the plot correctly.

With[{matsize = 50,
   nonzeros = 300,
   maxval = 0.5},
  mat = Table[0., {matsize},
      Module[{i, j, val},
    Do[val = Random[Real, {0, maxval}];
      i = Random[Integer, {1, matsize}];
      j = Random[Integer, {1, matsize}];
      mat[[i,j]] = If[j >= i, val, -val],

The following plots the matrix:

   ColorFunction -> colorfun[mat],
   ColorFunctionScaling -> False,
   Background -> RGBColor[0.980407, 0.941206, 0.902005],
   PlotLabel -> "Sparse Matrix Plot",
   ImageSize -> 500];

David Park
djmp at

> -----Original Message-----
> To: mathgroup at
> Subject: [mg28507] [mg28497] Two questions concerning ListDensityPlot ...
> Dear Mathematica experts,
> I'm actually trying to visualize sparsity patterns of matrixes using
> Mathematica's ListDensityPlot. However, doing so I have uncounted two
> problems ...
> 1. Given a (sparse) matrix A, I'm trying to establish a one-to-one
> correspondence between the plot and the matrix it is based on,
> i.e. I want
> the A[[1,1]] element to be plotted at the upper left and
> A[[Dimensions[A][[1]],Dimensions[A][[2]]]] at the lower right
> corner.  I've
> realized this by plotting
> Partition[Reverse@Flatten[A],Dimensions[A][[2]]]
> instead of A. However, doing so, I do not succeed in adjusting the labels
> appropriately since setting
> MeshRange->{{0,Dimensions[A][[1]]},{Dimensions[A][[2]],0}} does
> not invert
> the numbering of the ordinate as I've expected. Therefor my question is:
> How can I plot the matrix preserving the one-to-one correspondence and
> adjust the mesh such that the upper left corner corresponds to
> x=1, y=1 and
> the lower right to x=Dimensions[A][[2]], y=Dimensions[A][[1]]?
> 2. I'm desperately looking for a color function that allows the
> intermediate values to be kept white, while maxima and minima are colored
> red and blue respectively with the "color  intensity" indicating their
> absolute value. Applied to my sparse matrix problem I want the negative
> entries to be blue, the positive to be red whereas the majority
> of entries
> corresponding to zero should remain white. By the way, any suggestions
> concerning the visualization of complex valued entries are also highly
> appreciated. Is there an easy way to keep the phase information?
> Sincerely,
> Kattnig
> two questions concerning ListDensityPlot

  • Prev by Date: RE: Two questions concerning ListDensityPlot ...
  • Next by Date: RE: Plot DiracDelta[]
  • Previous by thread: RE: Two questions concerning ListDensityPlot ...
  • Next by thread: Help on solving simultaneous non-linear equations using FindRoot.