开发者

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 -&g开发者_如何转开发t; 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],
 # &
 ]

FrameTicks->Automatic in ClickPane causes constant processor activity

Switching to FrameTicks -> None stops the core activity.

FrameTicks->Automatic in ClickPane causes constant processor activity

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:

FrameTicks->Automatic in ClickPane causes constant processor activity

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?

FrameTicks->Automatic in ClickPane causes constant processor activity


Win XP Mma 8.0

FrameTicks->Automatic in ClickPane causes constant processor activity

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


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.


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.

FrameTicks->Automatic in ClickPane causes constant processor activity

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜