MathGroup Archive 2008

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

Search the Archive

Re: Problem with Mesh for MatrixPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89847] Re: Problem with Mesh for MatrixPlot
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sun, 22 Jun 2008 03:25:26 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <g3fvte$krt$1@smc.vnet.net>

Thibaut Jonckheere wrote:

> Dear group,
> 
> I have a large matrix, which has a block structure. In a MatrixPlot of 
> the matrix, I want to show the blocks by plotting mesh lines at the 
> block boundaries only. However, this seems to work well only for small 
> matrices, and not for larger matrices.
> 
> Here is a simple example showing the problem:
> 
> n1 = 3; n2 = 5;
> ntot = n1 n2;
> mymat = SparseArray[{Band[{1, 1}] -> 0.87, Band[{1, 2}] -> -0.3,
>     Band[{2, 1}] -> 0.3}, {ntot, ntot}];
> MatrixPlot[mymat,
>  Mesh -> {Table[n2*i, {i, 1, n1 - 1}], Table[n2*i, {i, 1, n1 - 1}]}]
> 
> 
> With these small values of n1 and n2, the result is as expected,showing 
> the 5x5 blocks. However, when I increase the values of n1 and n2 (for 
> example n1=13 and n2 =15), the meshlines are not shown on the whole 
> matrice width (they don't go further than approx. 90).
> 
> Note that the problem is also visible with the simple command:
> MatrixPlot[mymat, Mesh -> All].
> 
> 
> Is there something I am doing wrong, or is this a bug in the Mesh option 
> of MatrixPlot ?
> 
> Thank you for your help.
> 
> 
> Thibaut Jonckheere
> 
> NB: I use Mathematica 6.0.1.0 on Win Xp (32 bit), and also on Linux, and 
> the problem is present in both cases.

Hi Thibaut,

This is neither a bug nor a mistake of yours. By default, MatrixPlot[] 
downsamples the number of points displayed to keep the *structure* of 
the matrix visible. In other words, the default behavior is to preserve 
the overall shape over the accuracy (if measured by the number of points 
displayed).

You can control this behavior by setting explicitly the number of points 
to be displayed thanks to the option *MaxPlotPoints*. In the example 
below, the first plot uses the default value MaxPlotPoints -> Automatic, 
whereas the second uses MaxPlotPoints -> Infinity.

You will see that the second plot displays all the mesh lines but the 
diagonal (the interesting part of the matrix) is less visible.

n1 = 13; n2 = 15;
ntot = n1 n2;
mymat = SparseArray[{Band[{1, 1}] -> 0.87, Band[{1, 2}] -> -0.3,
     Band[{2, 1}] -> 0.3}, {ntot, ntot}];

MatrixPlot[mymat,
  Mesh -> {Table[n2*i, {i, 1, n1 - 1}], Table[n2*i, {i, 1, n1 - 1}]}]

MatrixPlot[mymat, MaxPlotPoints -> Infinity,
  Mesh -> {Table[n2*i, {i, 1, n1 - 1}], Table[n2*i, {i, 1, n1 - 1}]}]


Regards,
-- Jean-Marc


  • Prev by Date: Re: Insight into Solve...
  • Next by Date: Re: Insight into Solve...
  • Previous by thread: Re: Problem with Mesh for MatrixPlot
  • Next by thread: Re: Combining pure functions to produce a new pure