如何加速动态显示带有自定义刻度的图形?

时间:2011-06-15 23:05:18

标签: wolfram-mathematica

以下内容改编自现实世界代码:

ticks = Join[
   Table[{i, Style[i, 10, Background -> White], {.04, 0}}, {i, 0, 20, 
     1}],
   Table[{i, Null, {.01, 0}}, {i, 0, 20, 0.1}],
   Table[{i, Null, {.025, 0}}, {i, 0, 20, 0.5}]
   ];
loc = {1, 1};
LocatorPane[
 Dynamic[loc, loc[[2]] = #[[2]]; &],
 Dynamic@Show[
   Graphics[{Dashed, 
     Line[{{loc[[1]] - 0.5, loc[[2]]}, {0, loc[[2]]}}]}],
   ImageSize -> 300, PlotRange -> {{-10, 10}, {0, 20}}, 
   Axes -> {False, True}, AxesOrigin -> {0, 0}, 
   Ticks -> {Automatic, ticks}
   ]]

我遇到的问题是,当我使用自定义刻度时,更新(移动定位器)变得比使用自动刻度(Ticks -> {Automatic, Automatic})慢得多。我怎么能避免我认为是重建时间的嘀嗒声呢?

(我需要Dynamic@Show[...]用于此代码示例中未显示的其他更新原因。)

1 个答案:

答案 0 :(得分:3)

仅作为移动内部Dynamic的示例:

ticks = Join[
   Table[{i, Style[i, 10, Background -> White], {.04, 0}}, {i, 0, 20, 
     1}], Table[{i, Null, {.01, 0}}, {i, 0, 20, 0.1}], 
   Table[{i, Null, {.025, 0}}, {i, 0, 20, 0.5}]];
loc = {1, 1};
LocatorPane[Dynamic[loc, loc[[2]] = #[[2]]; &], 
 Show[Graphics[
   Dynamic@{Dashed, Line[{{loc[[1]] - 3, loc[[2]]}, {3, loc[[2]]}}]}],
   ImageSize -> 300, PlotRange -> {{-10, 10}, {0, 20}}, 
  Axes -> {False, True}, AxesOrigin -> {0, 0}, 
  Ticks -> {Automatic, ticks}]]

如果不了解您计划的其余部分,我将无法提供帮助。