Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FrameTicks->Automatic in ClickPane causes constant processor activity

I discovered that a MatrixPlot in a ClickPane causes one of my processor cores to cycle at about 50% activity if the option FrameTicks -> Automatic is present. I have cut down the code to the following (which doesn't do anything really):

a = ConstantArray[0, {2, 11}];
ClickPane[
 Dynamic@
  MatrixPlot[a, FrameTicks -> Automatic],
 # &
 ]

enter image description here

Switching to FrameTicks -> None stops the core activity.

enter image description here

To study the processor behavior I let a Clock cycle between None and Automatic every 20 secs (remove the above ClickPane first):

ClickPane[
 Dynamic@
  MatrixPlot[a, FrameTicks -> ft],
 # &
 ]
Dynamic[ft = {Automatic, None}[[Clock[{1, 2, 1}, 20]]]]

This gives me the following processor activity display:

enter image description here

This is on my Win7-64 / MMA 8.0.1 system.

My questions are:

  • Is this reproducible on other systems?
  • Am I doing something wrong or is this a bug?
  • Why does the bare MatrixPlot[a] (without any FrameTicks setting whatsoever) have these odd-looking frame tick choices?

enter image description here

like image 259
Sjoerd C. de Vries Avatar asked Sep 23 '11 15:09

Sjoerd C. de Vries


3 Answers

Win XP Mma 8.0

enter image description here

The missed peaks correspond to times when the notebook was hidden by another window. Losing focus does not stop the CPU draining.

like image 107
Dr. belisarius Avatar answered Nov 20 '22 05:11

Dr. belisarius


It seems that the Automatic setting of the FrameTicks option changes an internal variable that can be seen by Dynamic. It is apparently (and I think erroneously) not localized. This causes a complete re-evaluation of the argument of the Dynamic.

A workaround would be to add Refresh, which enables the use of TrackedSymbols, so that we can restrict triggering to just the variables we're interested in, in this case array a and the FrameTicks options value ft:

ClickPane[
 Dynamic@
  Refresh[
   MatrixPlot[a, FrameTicks -> ft],
   TrackedSymbols -> {a, ft}],
 # &
 ]
Dynamic[ft = {Automatic, None}[[Clock[{1, 2, 1}, 20]]]]

My processor status stays flat at close to zero now.

like image 32
Sjoerd C. de Vries Avatar answered Nov 20 '22 05:11

Sjoerd C. de Vries


Confirmed also on Mac OS X 10.6, Mathematica 8.0.1.

I thought at first that this was something to do with the kernel having to recalculate where the ticks went, every time FrameTicks->Automatic option was set.

So I tried this and got the same result. Likewise for ArrayPlot.

With[{fta = FrameTicks /. 
    FullForm[MatrixPlot[a, FrameTicks -> Automatic]][[1, 4]]},
 ClickPane[Dynamic@MatrixPlot[a, FrameTicks -> ft], # &]
  Dynamic[ft = {fta, None}[[Clock[{1, 2, 1}, 20]]]] ] 

But not for this plot - CPU usage barely moved between the two states.:

ClickPane[
 Dynamic@Plot[Sin[x], {x, 0, 6 Pi}, Frame -> True, 
   FrameTicks -> ft], # &]
Dynamic[ft = {Automatic, None}[[Clock[{1, 2, 1}, 20]]]]

I can only surmise that there must be some inefficiency in the way FrameTicks are displayed on these raster-type plot.

In answer to your third question, the odd tick choice doesn't reproduce on my system.

enter image description here

like image 2
Verbeia Avatar answered Nov 20 '22 06:11

Verbeia