Plot values of matrixplot as well as the matrixplot itself inside Manipulate [duplicate]











up vote
5
down vote

favorite













This question already has an answer here:




  • ArrayPlot with cells labeled by corresponding values

    1 answer




Given a MatrixPlot inside a Manipulate, say some $M(t)$ where $M_{ij}$ real for all entries, is there a way to show the values of each $M_{ij}$ inside matrix plot whilst the Manipulate runs?










share|improve this question















marked as duplicate by Edmund, Henrik Schumacher, m_goldberg, LCarvalho, Öskå Nov 15 at 6:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Sorry all I might have been unclear, what I mean is, say, given the 2x2 rotation matrix {{cos a t, sin a t}{-sin a t, cos a t}}, how can one display their values as manipulate varies wrt a?
    – MKF
    Nov 10 at 13:45










  • This just being an example
    – MKF
    Nov 10 at 16:38










  • mathematica.stackexchange.com/questions/9884/… solved it! thanks!
    – MKF
    Nov 10 at 16:50















up vote
5
down vote

favorite













This question already has an answer here:




  • ArrayPlot with cells labeled by corresponding values

    1 answer




Given a MatrixPlot inside a Manipulate, say some $M(t)$ where $M_{ij}$ real for all entries, is there a way to show the values of each $M_{ij}$ inside matrix plot whilst the Manipulate runs?










share|improve this question















marked as duplicate by Edmund, Henrik Schumacher, m_goldberg, LCarvalho, Öskå Nov 15 at 6:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Sorry all I might have been unclear, what I mean is, say, given the 2x2 rotation matrix {{cos a t, sin a t}{-sin a t, cos a t}}, how can one display their values as manipulate varies wrt a?
    – MKF
    Nov 10 at 13:45










  • This just being an example
    – MKF
    Nov 10 at 16:38










  • mathematica.stackexchange.com/questions/9884/… solved it! thanks!
    – MKF
    Nov 10 at 16:50













up vote
5
down vote

favorite









up vote
5
down vote

favorite












This question already has an answer here:




  • ArrayPlot with cells labeled by corresponding values

    1 answer




Given a MatrixPlot inside a Manipulate, say some $M(t)$ where $M_{ij}$ real for all entries, is there a way to show the values of each $M_{ij}$ inside matrix plot whilst the Manipulate runs?










share|improve this question
















This question already has an answer here:




  • ArrayPlot with cells labeled by corresponding values

    1 answer




Given a MatrixPlot inside a Manipulate, say some $M(t)$ where $M_{ij}$ real for all entries, is there a way to show the values of each $M_{ij}$ inside matrix plot whilst the Manipulate runs?





This question already has an answer here:




  • ArrayPlot with cells labeled by corresponding values

    1 answer








graphics matrix






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 1:11









kglr

173k8196401




173k8196401










asked Nov 9 at 23:30









MKF

1414




1414




marked as duplicate by Edmund, Henrik Schumacher, m_goldberg, LCarvalho, Öskå Nov 15 at 6:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Edmund, Henrik Schumacher, m_goldberg, LCarvalho, Öskå Nov 15 at 6:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Sorry all I might have been unclear, what I mean is, say, given the 2x2 rotation matrix {{cos a t, sin a t}{-sin a t, cos a t}}, how can one display their values as manipulate varies wrt a?
    – MKF
    Nov 10 at 13:45










  • This just being an example
    – MKF
    Nov 10 at 16:38










  • mathematica.stackexchange.com/questions/9884/… solved it! thanks!
    – MKF
    Nov 10 at 16:50


















  • Sorry all I might have been unclear, what I mean is, say, given the 2x2 rotation matrix {{cos a t, sin a t}{-sin a t, cos a t}}, how can one display their values as manipulate varies wrt a?
    – MKF
    Nov 10 at 13:45










  • This just being an example
    – MKF
    Nov 10 at 16:38










  • mathematica.stackexchange.com/questions/9884/… solved it! thanks!
    – MKF
    Nov 10 at 16:50
















Sorry all I might have been unclear, what I mean is, say, given the 2x2 rotation matrix {{cos a t, sin a t}{-sin a t, cos a t}}, how can one display their values as manipulate varies wrt a?
– MKF
Nov 10 at 13:45




Sorry all I might have been unclear, what I mean is, say, given the 2x2 rotation matrix {{cos a t, sin a t}{-sin a t, cos a t}}, how can one display their values as manipulate varies wrt a?
– MKF
Nov 10 at 13:45












This just being an example
– MKF
Nov 10 at 16:38




This just being an example
– MKF
Nov 10 at 16:38












mathematica.stackexchange.com/questions/9884/… solved it! thanks!
– MKF
Nov 10 at 16:50




mathematica.stackexchange.com/questions/9884/… solved it! thanks!
– MKF
Nov 10 at 16:50










2 Answers
2






active

oldest

votes

















up vote
5
down vote













Update: Using the example matrix from the comments:



Manipulate[With[{mat = {{Cos[ a t], Sin [a t]}, {-Sin[ a t], Cos[ a t]}}}, 
MatrixPlot[mat, Mesh -> All, ImageSize -> 1 -> 100,
Epilog -> Dynamic[MapIndexed[Text[Style[Round[#, .01], Large,
If[Abs[#] >= .5, White, Black]], {#2[[1]], 3 - #2[[2]]} - .5] &, mat, {2}]]]],
{{a, 1/2}, 0, 1}, {{t, 0}, -2 Pi, Pi}]


enter image description here



Original answer:



Using a Slider to change the dimensions of the matrix and EventHandler to increase (left mouse click) / decrease (right mouse click) values of matrix elements:



DynamicModule[{m = ConstantArray[0, {20, 20}]},
Manipulate[mat = m[[;; n, ;; n]];
Dynamic@EventHandler[
MatrixPlot[mat, Mesh -> All, ImageSize -> 1 -> 50,
DataReversed -> True,
Epilog -> Dynamic[MapIndexed[Text[Style[#, Large], Reverse@#2 - .5] &, mat, {2}]]],
{{"MouseClicked", 1} :> With[{p = Reverse @ Ceiling @ MousePosition["Graphics"]},
m[[## & @@ p]] += 1],
{"MouseClicked", 2} :> With[{p = Reverse @ Ceiling @ MousePosition["Graphics"]},
m[[## & @@ p]] -= 1]}],
{{n, 5}, 2, 20, 1}]]


enter image description here



enter image description here






share|improve this answer






























    up vote
    3
    down vote













    Here is using Graphics



    SeedRandom@2;
    matrix = RandomInteger[10, {5, 5}];
    MatrixForm@matrix



    $left(begin{array}{ccccc}
    8 & 4 & 5 & 4 & 7 \
    4 & 0 & 1 & 0 & 4 \
    3 & 7 & 3 & 0 & 2 \
    7 & 8 & 7 & 9 & 3 \
    6 & 2 & 3 & 8 & 9 \
    end{array}right)$




    data = Join @@ Reverse@Table[{i, j}, {j, 5}, {i, 1, 5}];
    values = Flatten@matrix;
    minMax = MinMax@values;
    data2 = Flatten /@ Partition[Riffle[values, data], 2];

    Legended[Graphics[{EdgeForm[{Black}],
    ColorData["DarkRainbow"][Rescale[First[#], minMax]],
    Rectangle[Rest[#]], Black,
    Text[First[#], Rest[#] + {0.5, 0.5}]} & /@ data2],
    BarLegend[{"DarkRainbow", minMax}]]


    enter image description here



    If you want to use MatrixPlot



    Overlay[{MatrixPlot[matrix, PlotRangePadding -> None, 
    ImagePadding -> None],
    Graphics[{Opacity@0, Rectangle[Rest[#]], Opacity@1, Black,
    Text[First[#], Rest[#] + {0.5, 0.5}]} & /@ data2,
    PlotRangePadding -> None]}]


    enter image description here






    share|improve this answer





















    • Please don't use JPG for non-photographic images! :)
      – Andreas Rejbrand
      Nov 10 at 11:10


















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote













    Update: Using the example matrix from the comments:



    Manipulate[With[{mat = {{Cos[ a t], Sin [a t]}, {-Sin[ a t], Cos[ a t]}}}, 
    MatrixPlot[mat, Mesh -> All, ImageSize -> 1 -> 100,
    Epilog -> Dynamic[MapIndexed[Text[Style[Round[#, .01], Large,
    If[Abs[#] >= .5, White, Black]], {#2[[1]], 3 - #2[[2]]} - .5] &, mat, {2}]]]],
    {{a, 1/2}, 0, 1}, {{t, 0}, -2 Pi, Pi}]


    enter image description here



    Original answer:



    Using a Slider to change the dimensions of the matrix and EventHandler to increase (left mouse click) / decrease (right mouse click) values of matrix elements:



    DynamicModule[{m = ConstantArray[0, {20, 20}]},
    Manipulate[mat = m[[;; n, ;; n]];
    Dynamic@EventHandler[
    MatrixPlot[mat, Mesh -> All, ImageSize -> 1 -> 50,
    DataReversed -> True,
    Epilog -> Dynamic[MapIndexed[Text[Style[#, Large], Reverse@#2 - .5] &, mat, {2}]]],
    {{"MouseClicked", 1} :> With[{p = Reverse @ Ceiling @ MousePosition["Graphics"]},
    m[[## & @@ p]] += 1],
    {"MouseClicked", 2} :> With[{p = Reverse @ Ceiling @ MousePosition["Graphics"]},
    m[[## & @@ p]] -= 1]}],
    {{n, 5}, 2, 20, 1}]]


    enter image description here



    enter image description here






    share|improve this answer



























      up vote
      5
      down vote













      Update: Using the example matrix from the comments:



      Manipulate[With[{mat = {{Cos[ a t], Sin [a t]}, {-Sin[ a t], Cos[ a t]}}}, 
      MatrixPlot[mat, Mesh -> All, ImageSize -> 1 -> 100,
      Epilog -> Dynamic[MapIndexed[Text[Style[Round[#, .01], Large,
      If[Abs[#] >= .5, White, Black]], {#2[[1]], 3 - #2[[2]]} - .5] &, mat, {2}]]]],
      {{a, 1/2}, 0, 1}, {{t, 0}, -2 Pi, Pi}]


      enter image description here



      Original answer:



      Using a Slider to change the dimensions of the matrix and EventHandler to increase (left mouse click) / decrease (right mouse click) values of matrix elements:



      DynamicModule[{m = ConstantArray[0, {20, 20}]},
      Manipulate[mat = m[[;; n, ;; n]];
      Dynamic@EventHandler[
      MatrixPlot[mat, Mesh -> All, ImageSize -> 1 -> 50,
      DataReversed -> True,
      Epilog -> Dynamic[MapIndexed[Text[Style[#, Large], Reverse@#2 - .5] &, mat, {2}]]],
      {{"MouseClicked", 1} :> With[{p = Reverse @ Ceiling @ MousePosition["Graphics"]},
      m[[## & @@ p]] += 1],
      {"MouseClicked", 2} :> With[{p = Reverse @ Ceiling @ MousePosition["Graphics"]},
      m[[## & @@ p]] -= 1]}],
      {{n, 5}, 2, 20, 1}]]


      enter image description here



      enter image description here






      share|improve this answer

























        up vote
        5
        down vote










        up vote
        5
        down vote









        Update: Using the example matrix from the comments:



        Manipulate[With[{mat = {{Cos[ a t], Sin [a t]}, {-Sin[ a t], Cos[ a t]}}}, 
        MatrixPlot[mat, Mesh -> All, ImageSize -> 1 -> 100,
        Epilog -> Dynamic[MapIndexed[Text[Style[Round[#, .01], Large,
        If[Abs[#] >= .5, White, Black]], {#2[[1]], 3 - #2[[2]]} - .5] &, mat, {2}]]]],
        {{a, 1/2}, 0, 1}, {{t, 0}, -2 Pi, Pi}]


        enter image description here



        Original answer:



        Using a Slider to change the dimensions of the matrix and EventHandler to increase (left mouse click) / decrease (right mouse click) values of matrix elements:



        DynamicModule[{m = ConstantArray[0, {20, 20}]},
        Manipulate[mat = m[[;; n, ;; n]];
        Dynamic@EventHandler[
        MatrixPlot[mat, Mesh -> All, ImageSize -> 1 -> 50,
        DataReversed -> True,
        Epilog -> Dynamic[MapIndexed[Text[Style[#, Large], Reverse@#2 - .5] &, mat, {2}]]],
        {{"MouseClicked", 1} :> With[{p = Reverse @ Ceiling @ MousePosition["Graphics"]},
        m[[## & @@ p]] += 1],
        {"MouseClicked", 2} :> With[{p = Reverse @ Ceiling @ MousePosition["Graphics"]},
        m[[## & @@ p]] -= 1]}],
        {{n, 5}, 2, 20, 1}]]


        enter image description here



        enter image description here






        share|improve this answer














        Update: Using the example matrix from the comments:



        Manipulate[With[{mat = {{Cos[ a t], Sin [a t]}, {-Sin[ a t], Cos[ a t]}}}, 
        MatrixPlot[mat, Mesh -> All, ImageSize -> 1 -> 100,
        Epilog -> Dynamic[MapIndexed[Text[Style[Round[#, .01], Large,
        If[Abs[#] >= .5, White, Black]], {#2[[1]], 3 - #2[[2]]} - .5] &, mat, {2}]]]],
        {{a, 1/2}, 0, 1}, {{t, 0}, -2 Pi, Pi}]


        enter image description here



        Original answer:



        Using a Slider to change the dimensions of the matrix and EventHandler to increase (left mouse click) / decrease (right mouse click) values of matrix elements:



        DynamicModule[{m = ConstantArray[0, {20, 20}]},
        Manipulate[mat = m[[;; n, ;; n]];
        Dynamic@EventHandler[
        MatrixPlot[mat, Mesh -> All, ImageSize -> 1 -> 50,
        DataReversed -> True,
        Epilog -> Dynamic[MapIndexed[Text[Style[#, Large], Reverse@#2 - .5] &, mat, {2}]]],
        {{"MouseClicked", 1} :> With[{p = Reverse @ Ceiling @ MousePosition["Graphics"]},
        m[[## & @@ p]] += 1],
        {"MouseClicked", 2} :> With[{p = Reverse @ Ceiling @ MousePosition["Graphics"]},
        m[[## & @@ p]] -= 1]}],
        {{n, 5}, 2, 20, 1}]]


        enter image description here



        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 11 at 4:25

























        answered Nov 10 at 1:06









        kglr

        173k8196401




        173k8196401






















            up vote
            3
            down vote













            Here is using Graphics



            SeedRandom@2;
            matrix = RandomInteger[10, {5, 5}];
            MatrixForm@matrix



            $left(begin{array}{ccccc}
            8 & 4 & 5 & 4 & 7 \
            4 & 0 & 1 & 0 & 4 \
            3 & 7 & 3 & 0 & 2 \
            7 & 8 & 7 & 9 & 3 \
            6 & 2 & 3 & 8 & 9 \
            end{array}right)$




            data = Join @@ Reverse@Table[{i, j}, {j, 5}, {i, 1, 5}];
            values = Flatten@matrix;
            minMax = MinMax@values;
            data2 = Flatten /@ Partition[Riffle[values, data], 2];

            Legended[Graphics[{EdgeForm[{Black}],
            ColorData["DarkRainbow"][Rescale[First[#], minMax]],
            Rectangle[Rest[#]], Black,
            Text[First[#], Rest[#] + {0.5, 0.5}]} & /@ data2],
            BarLegend[{"DarkRainbow", minMax}]]


            enter image description here



            If you want to use MatrixPlot



            Overlay[{MatrixPlot[matrix, PlotRangePadding -> None, 
            ImagePadding -> None],
            Graphics[{Opacity@0, Rectangle[Rest[#]], Opacity@1, Black,
            Text[First[#], Rest[#] + {0.5, 0.5}]} & /@ data2,
            PlotRangePadding -> None]}]


            enter image description here






            share|improve this answer





















            • Please don't use JPG for non-photographic images! :)
              – Andreas Rejbrand
              Nov 10 at 11:10















            up vote
            3
            down vote













            Here is using Graphics



            SeedRandom@2;
            matrix = RandomInteger[10, {5, 5}];
            MatrixForm@matrix



            $left(begin{array}{ccccc}
            8 & 4 & 5 & 4 & 7 \
            4 & 0 & 1 & 0 & 4 \
            3 & 7 & 3 & 0 & 2 \
            7 & 8 & 7 & 9 & 3 \
            6 & 2 & 3 & 8 & 9 \
            end{array}right)$




            data = Join @@ Reverse@Table[{i, j}, {j, 5}, {i, 1, 5}];
            values = Flatten@matrix;
            minMax = MinMax@values;
            data2 = Flatten /@ Partition[Riffle[values, data], 2];

            Legended[Graphics[{EdgeForm[{Black}],
            ColorData["DarkRainbow"][Rescale[First[#], minMax]],
            Rectangle[Rest[#]], Black,
            Text[First[#], Rest[#] + {0.5, 0.5}]} & /@ data2],
            BarLegend[{"DarkRainbow", minMax}]]


            enter image description here



            If you want to use MatrixPlot



            Overlay[{MatrixPlot[matrix, PlotRangePadding -> None, 
            ImagePadding -> None],
            Graphics[{Opacity@0, Rectangle[Rest[#]], Opacity@1, Black,
            Text[First[#], Rest[#] + {0.5, 0.5}]} & /@ data2,
            PlotRangePadding -> None]}]


            enter image description here






            share|improve this answer





















            • Please don't use JPG for non-photographic images! :)
              – Andreas Rejbrand
              Nov 10 at 11:10













            up vote
            3
            down vote










            up vote
            3
            down vote









            Here is using Graphics



            SeedRandom@2;
            matrix = RandomInteger[10, {5, 5}];
            MatrixForm@matrix



            $left(begin{array}{ccccc}
            8 & 4 & 5 & 4 & 7 \
            4 & 0 & 1 & 0 & 4 \
            3 & 7 & 3 & 0 & 2 \
            7 & 8 & 7 & 9 & 3 \
            6 & 2 & 3 & 8 & 9 \
            end{array}right)$




            data = Join @@ Reverse@Table[{i, j}, {j, 5}, {i, 1, 5}];
            values = Flatten@matrix;
            minMax = MinMax@values;
            data2 = Flatten /@ Partition[Riffle[values, data], 2];

            Legended[Graphics[{EdgeForm[{Black}],
            ColorData["DarkRainbow"][Rescale[First[#], minMax]],
            Rectangle[Rest[#]], Black,
            Text[First[#], Rest[#] + {0.5, 0.5}]} & /@ data2],
            BarLegend[{"DarkRainbow", minMax}]]


            enter image description here



            If you want to use MatrixPlot



            Overlay[{MatrixPlot[matrix, PlotRangePadding -> None, 
            ImagePadding -> None],
            Graphics[{Opacity@0, Rectangle[Rest[#]], Opacity@1, Black,
            Text[First[#], Rest[#] + {0.5, 0.5}]} & /@ data2,
            PlotRangePadding -> None]}]


            enter image description here






            share|improve this answer












            Here is using Graphics



            SeedRandom@2;
            matrix = RandomInteger[10, {5, 5}];
            MatrixForm@matrix



            $left(begin{array}{ccccc}
            8 & 4 & 5 & 4 & 7 \
            4 & 0 & 1 & 0 & 4 \
            3 & 7 & 3 & 0 & 2 \
            7 & 8 & 7 & 9 & 3 \
            6 & 2 & 3 & 8 & 9 \
            end{array}right)$




            data = Join @@ Reverse@Table[{i, j}, {j, 5}, {i, 1, 5}];
            values = Flatten@matrix;
            minMax = MinMax@values;
            data2 = Flatten /@ Partition[Riffle[values, data], 2];

            Legended[Graphics[{EdgeForm[{Black}],
            ColorData["DarkRainbow"][Rescale[First[#], minMax]],
            Rectangle[Rest[#]], Black,
            Text[First[#], Rest[#] + {0.5, 0.5}]} & /@ data2],
            BarLegend[{"DarkRainbow", minMax}]]


            enter image description here



            If you want to use MatrixPlot



            Overlay[{MatrixPlot[matrix, PlotRangePadding -> None, 
            ImagePadding -> None],
            Graphics[{Opacity@0, Rectangle[Rest[#]], Opacity@1, Black,
            Text[First[#], Rest[#] + {0.5, 0.5}]} & /@ data2,
            PlotRangePadding -> None]}]


            enter image description here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 10 at 0:13









            Okkes Dulgerci

            3,6281716




            3,6281716












            • Please don't use JPG for non-photographic images! :)
              – Andreas Rejbrand
              Nov 10 at 11:10


















            • Please don't use JPG for non-photographic images! :)
              – Andreas Rejbrand
              Nov 10 at 11:10
















            Please don't use JPG for non-photographic images! :)
            – Andreas Rejbrand
            Nov 10 at 11:10




            Please don't use JPG for non-photographic images! :)
            – Andreas Rejbrand
            Nov 10 at 11:10



            Popular posts from this blog

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)