3
$\begingroup$

If I enter MatrixPlot[{{1, 2}, {3, 4}}],it shows:enter image description here

How can I combine this with a 2D slider,when I move the slider to a region,it could show me the value that correspond to the matrix?

$\endgroup$
7
  • 2
    $\begingroup$ See the answers here $\endgroup$
    – Jason B.
    Aug 12, 2016 at 18:18
  • $\begingroup$ By "slider", do you actually mean "tooltip"? $\endgroup$ Aug 12, 2016 at 18:26
  • $\begingroup$ @J.M. - I actually like faleichik's Dynamic version in the linked post (duplicate?) better than the Tooltip-based accepted answer $\endgroup$
    – Jason B.
    Aug 12, 2016 at 18:45
  • $\begingroup$ I think it's a dupe, @Jason, but I'll let other people vote... and yes, faleichik's solution is lovely. $\endgroup$ Aug 12, 2016 at 18:46
  • $\begingroup$ I hadn't seen the first comment, excuse me. $\endgroup$
    – BoLe
    Aug 12, 2016 at 18:48

1 Answer 1

2
$\begingroup$

By "slider", do you mean locator?

m = RandomInteger[{1, 100}, {10, 10}];

With[{eps = .1},
 DynamicModule[{p = {.5, .5}, lab},
  lab[{x_Integer, y_Integer}] :=
   Style[StringJoin[{"value: ",
      ToString[m[[Length[m] - y, x + 1]]]}], 16, Bold];
  LocatorPane[
   Dynamic[p],
   MatrixPlot[m,
    PlotLabel -> Dynamic[lab@Floor@p]],
   {{eps, eps}, Dimensions[m] - eps}]]]

enter image description here

$\endgroup$
1
  • $\begingroup$ That's exactly what I want! Amazing! Thank you very much. $\endgroup$
    – 蔡漢倫
    Aug 13, 2016 at 0:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.