3 replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
source | link

I want to plot a heatmap of a set of real points of the interval [0,1] - i.e., to display their linear density in the sense of a smoothed histogram. The idea I have come up so far is to use the heatMap function introduced herehere:

heatMap[data_, opts : OptionsPattern[]] := Module[
{n, size, xRange, pr},
n = "Points" /. {opts} /. {"Points" -> 100};
pr = PlotRange /. {opts} /. {PlotRange :> 
    Map[{Min[#], Max[#]} &, Transpose[data]]};
xRange = -Subtract @@ pr[[1]];
size = Floor[
  n ("Radius" /. {opts} /. {"Radius" -> xRange/6})/xRange];
Graphics[{
  Inset[
   ArrayPlot[
    Rescale@GaussianFilter[
      ImageData@ColorNegate@ColorConvert[
         Rasterize[Graphics[Point[data],
           Background -> White,
           PlotRangePadding -> 0,
           ImagePadding -> 0,
           ImageMargins -> 0,
           PlotRange -> pr],
          "Image", ImageSize -> n], "GrayScale"],
      {3 size, size}, Padding -> 0],
    ColorFunction ->  
     (ColorFunction /. {opts} /. 
      {ColorFunction -> 
       ColorData["LakeColors"]
      }
     ),
    ImagePadding -> 0,
    PlotRangePadding -> 0, Frame -> False],
   pr[[All, 1]], {0, 0}, xRange]},
 PlotRange -> pr, Frame -> True, PlotRangePadding -> Scaled[.02]
 ]
]

and converting the one dimensional data to two dimensions:

data = RandomReal[{0, 1}, 100];
data = {#, 0} & /@ data;

heatMap[data, "Points" -> 300, "Radius" -> .01, PlotRange -> {{0, 1}, {0, .05}}]

sample plot

How do I have to modify heatMap to draw rectangles instead of points that blur at the edges? Or perhaps is there a shorter and more elegant way to draw a "heatline"?

I want to plot a heatmap of a set of real points of the interval [0,1] - i.e., to display their linear density in the sense of a smoothed histogram. The idea I have come up so far is to use the heatMap function introduced here:

heatMap[data_, opts : OptionsPattern[]] := Module[
{n, size, xRange, pr},
n = "Points" /. {opts} /. {"Points" -> 100};
pr = PlotRange /. {opts} /. {PlotRange :> 
    Map[{Min[#], Max[#]} &, Transpose[data]]};
xRange = -Subtract @@ pr[[1]];
size = Floor[
  n ("Radius" /. {opts} /. {"Radius" -> xRange/6})/xRange];
Graphics[{
  Inset[
   ArrayPlot[
    Rescale@GaussianFilter[
      ImageData@ColorNegate@ColorConvert[
         Rasterize[Graphics[Point[data],
           Background -> White,
           PlotRangePadding -> 0,
           ImagePadding -> 0,
           ImageMargins -> 0,
           PlotRange -> pr],
          "Image", ImageSize -> n], "GrayScale"],
      {3 size, size}, Padding -> 0],
    ColorFunction ->  
     (ColorFunction /. {opts} /. 
      {ColorFunction -> 
       ColorData["LakeColors"]
      }
     ),
    ImagePadding -> 0,
    PlotRangePadding -> 0, Frame -> False],
   pr[[All, 1]], {0, 0}, xRange]},
 PlotRange -> pr, Frame -> True, PlotRangePadding -> Scaled[.02]
 ]
]

and converting the one dimensional data to two dimensions:

data = RandomReal[{0, 1}, 100];
data = {#, 0} & /@ data;

heatMap[data, "Points" -> 300, "Radius" -> .01, PlotRange -> {{0, 1}, {0, .05}}]

sample plot

How do I have to modify heatMap to draw rectangles instead of points that blur at the edges? Or perhaps is there a shorter and more elegant way to draw a "heatline"?

I want to plot a heatmap of a set of real points of the interval [0,1] - i.e., to display their linear density in the sense of a smoothed histogram. The idea I have come up so far is to use the heatMap function introduced here:

heatMap[data_, opts : OptionsPattern[]] := Module[
{n, size, xRange, pr},
n = "Points" /. {opts} /. {"Points" -> 100};
pr = PlotRange /. {opts} /. {PlotRange :> 
    Map[{Min[#], Max[#]} &, Transpose[data]]};
xRange = -Subtract @@ pr[[1]];
size = Floor[
  n ("Radius" /. {opts} /. {"Radius" -> xRange/6})/xRange];
Graphics[{
  Inset[
   ArrayPlot[
    Rescale@GaussianFilter[
      ImageData@ColorNegate@ColorConvert[
         Rasterize[Graphics[Point[data],
           Background -> White,
           PlotRangePadding -> 0,
           ImagePadding -> 0,
           ImageMargins -> 0,
           PlotRange -> pr],
          "Image", ImageSize -> n], "GrayScale"],
      {3 size, size}, Padding -> 0],
    ColorFunction ->  
     (ColorFunction /. {opts} /. 
      {ColorFunction -> 
       ColorData["LakeColors"]
      }
     ),
    ImagePadding -> 0,
    PlotRangePadding -> 0, Frame -> False],
   pr[[All, 1]], {0, 0}, xRange]},
 PlotRange -> pr, Frame -> True, PlotRangePadding -> Scaled[.02]
 ]
]

and converting the one dimensional data to two dimensions:

data = RandomReal[{0, 1}, 100];
data = {#, 0} & /@ data;

heatMap[data, "Points" -> 300, "Radius" -> .01, PlotRange -> {{0, 1}, {0, .05}}]

sample plot

How do I have to modify heatMap to draw rectangles instead of points that blur at the edges? Or perhaps is there a shorter and more elegant way to draw a "heatline"?

2 Added "verbal decoration" to clarify heatmap concept.
source | link

I want to plot a heatmap of a set of real points of the interval [0,1] - i.e., to display their linear density in the sense of a smoothed histogram. The idea I have come up so far is to use the heatMap function introduced here:

heatMap[data_, opts : OptionsPattern[]] := Module[
{n, size, xRange, pr},
n = "Points" /. {opts} /. {"Points" -> 100};
pr = PlotRange /. {opts} /. {PlotRange :> 
    Map[{Min[#], Max[#]} &, Transpose[data]]};
xRange = -Subtract @@ pr[[1]];
size = Floor[
  n ("Radius" /. {opts} /. {"Radius" -> xRange/6})/xRange];
Graphics[{
  Inset[
   ArrayPlot[
    Rescale@GaussianFilter[
      ImageData@ColorNegate@ColorConvert[
         Rasterize[Graphics[Point[data],
           Background -> White,
           PlotRangePadding -> 0,
           ImagePadding -> 0,
           ImageMargins -> 0,
           PlotRange -> pr],
          "Image", ImageSize -> n], "GrayScale"],
      {3 size, size}, Padding -> 0],
    ColorFunction ->  
     (ColorFunction /. {opts} /. 
      {ColorFunction -> 
       ColorData["LakeColors"]
      }
     ),
    ImagePadding -> 0,
    PlotRangePadding -> 0, Frame -> False],
   pr[[All, 1]], {0, 0}, xRange]},
 PlotRange -> pr, Frame -> True, PlotRangePadding -> Scaled[.02]
 ]
]

and converting the one dimensional data to two dimensions:

data = RandomReal[{0, 1}, 100];
data = {#, 0} & /@ data;

heatMap[data, "Points" -> 300, "Radius" -> .01, PlotRange -> {{0, 1}, {0, .05}}]

sample plot

How do I have to modify heatMap to draw rectangles instead of points that blur at the edges? Or perhaps is there a shorter and more elegant way to draw a "heatline"?

I want to plot a heatmap of a set of real points of the interval [0,1]. The idea I have come up so far is to use the heatMap function introduced here:

heatMap[data_, opts : OptionsPattern[]] := Module[
{n, size, xRange, pr},
n = "Points" /. {opts} /. {"Points" -> 100};
pr = PlotRange /. {opts} /. {PlotRange :> 
    Map[{Min[#], Max[#]} &, Transpose[data]]};
xRange = -Subtract @@ pr[[1]];
size = Floor[
  n ("Radius" /. {opts} /. {"Radius" -> xRange/6})/xRange];
Graphics[{
  Inset[
   ArrayPlot[
    Rescale@GaussianFilter[
      ImageData@ColorNegate@ColorConvert[
         Rasterize[Graphics[Point[data],
           Background -> White,
           PlotRangePadding -> 0,
           ImagePadding -> 0,
           ImageMargins -> 0,
           PlotRange -> pr],
          "Image", ImageSize -> n], "GrayScale"],
      {3 size, size}, Padding -> 0],
    ColorFunction ->  
     (ColorFunction /. {opts} /. 
      {ColorFunction -> 
       ColorData["LakeColors"]
      }
     ),
    ImagePadding -> 0,
    PlotRangePadding -> 0, Frame -> False],
   pr[[All, 1]], {0, 0}, xRange]},
 PlotRange -> pr, Frame -> True, PlotRangePadding -> Scaled[.02]
 ]
]

and converting the one dimensional data to two dimensions:

data = RandomReal[{0, 1}, 100];
data = {#, 0} & /@ data;

heatMap[data, "Points" -> 300, "Radius" -> .01, PlotRange -> {{0, 1}, {0, .05}}]

sample plot

How do I have to modify heatMap to draw rectangles instead of points that blur at the edges? Or perhaps is there a shorter and more elegant way to draw a "heatline"?

I want to plot a heatmap of a set of real points of the interval [0,1] - i.e., to display their linear density in the sense of a smoothed histogram. The idea I have come up so far is to use the heatMap function introduced here:

heatMap[data_, opts : OptionsPattern[]] := Module[
{n, size, xRange, pr},
n = "Points" /. {opts} /. {"Points" -> 100};
pr = PlotRange /. {opts} /. {PlotRange :> 
    Map[{Min[#], Max[#]} &, Transpose[data]]};
xRange = -Subtract @@ pr[[1]];
size = Floor[
  n ("Radius" /. {opts} /. {"Radius" -> xRange/6})/xRange];
Graphics[{
  Inset[
   ArrayPlot[
    Rescale@GaussianFilter[
      ImageData@ColorNegate@ColorConvert[
         Rasterize[Graphics[Point[data],
           Background -> White,
           PlotRangePadding -> 0,
           ImagePadding -> 0,
           ImageMargins -> 0,
           PlotRange -> pr],
          "Image", ImageSize -> n], "GrayScale"],
      {3 size, size}, Padding -> 0],
    ColorFunction ->  
     (ColorFunction /. {opts} /. 
      {ColorFunction -> 
       ColorData["LakeColors"]
      }
     ),
    ImagePadding -> 0,
    PlotRangePadding -> 0, Frame -> False],
   pr[[All, 1]], {0, 0}, xRange]},
 PlotRange -> pr, Frame -> True, PlotRangePadding -> Scaled[.02]
 ]
]

and converting the one dimensional data to two dimensions:

data = RandomReal[{0, 1}, 100];
data = {#, 0} & /@ data;

heatMap[data, "Points" -> 300, "Radius" -> .01, PlotRange -> {{0, 1}, {0, .05}}]

sample plot

How do I have to modify heatMap to draw rectangles instead of points that blur at the edges? Or perhaps is there a shorter and more elegant way to draw a "heatline"?

1
source | link

One-dimensional heatmap

I want to plot a heatmap of a set of real points of the interval [0,1]. The idea I have come up so far is to use the heatMap function introduced here:

heatMap[data_, opts : OptionsPattern[]] := Module[
{n, size, xRange, pr},
n = "Points" /. {opts} /. {"Points" -> 100};
pr = PlotRange /. {opts} /. {PlotRange :> 
    Map[{Min[#], Max[#]} &, Transpose[data]]};
xRange = -Subtract @@ pr[[1]];
size = Floor[
  n ("Radius" /. {opts} /. {"Radius" -> xRange/6})/xRange];
Graphics[{
  Inset[
   ArrayPlot[
    Rescale@GaussianFilter[
      ImageData@ColorNegate@ColorConvert[
         Rasterize[Graphics[Point[data],
           Background -> White,
           PlotRangePadding -> 0,
           ImagePadding -> 0,
           ImageMargins -> 0,
           PlotRange -> pr],
          "Image", ImageSize -> n], "GrayScale"],
      {3 size, size}, Padding -> 0],
    ColorFunction ->  
     (ColorFunction /. {opts} /. 
      {ColorFunction -> 
       ColorData["LakeColors"]
      }
     ),
    ImagePadding -> 0,
    PlotRangePadding -> 0, Frame -> False],
   pr[[All, 1]], {0, 0}, xRange]},
 PlotRange -> pr, Frame -> True, PlotRangePadding -> Scaled[.02]
 ]
]

and converting the one dimensional data to two dimensions:

data = RandomReal[{0, 1}, 100];
data = {#, 0} & /@ data;

heatMap[data, "Points" -> 300, "Radius" -> .01, PlotRange -> {{0, 1}, {0, .05}}]

sample plot

How do I have to modify heatMap to draw rectangles instead of points that blur at the edges? Or perhaps is there a shorter and more elegant way to draw a "heatline"?