Group Abstract Group Abstract

Message Boards Message Boards

0
|
8.9K Views
|
8 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Smooth heat map using ListDensityPlot of data in 6x6?

Posted 9 years ago
POSTED BY: Okkes Dulgerci
8 Replies
Posted 9 years ago

Here is what I did.

data={2.18756, 2.17447, 2.17031, 2.16801, 2.31719, 2.36214, 2.14151, \
2.13749, 2.13819, 2.14531, 2.35749, 2.40783, 2.18333, 2.16507, \
2.17598, 2.21962, 3.52217, 3.60957, 2.21752, 2.14844, 2.15905, \
2.76315, 3.70188, 3.83357, 2.25902, 2.17451, 2.18496, 2.83573, \
3.6727, 3.82887, 2.23612, 2.14, 2.17541, 2.76535, 3.61427, 3.80555};

g = ListInterpolation[data, InterpolationOrder -> 1];
data2 = g[#[[1]], #[[2]]] & /@ Tuples[Range@7, 2] // Quiet;
ListDensityPlot[Transpose@Partition[data2, 7], 
 ColorFunction -> "TemperatureMap", Frame -> True, Mesh -> 5, 
 InterpolationOrder -> 0, MeshStyle -> Black, FrameTicks -> False, 
 FrameLabel -> {"IPTG", "Rib"}, PlotLabel -> "Data Heat Map ", 
 PlotLegends -> 
  BarLegend[{"TemperatureMap", {1, 5}}, 
   LegendLabel -> 
    Placed["Fluorescence (MEPE)", Right, Rotate[#, 90 Degree] &], 
   LegendMarkerSize -> 170], ImageSize -> 200]

Which gives me exactly (more or less) ArrayPlot results. Note that data2 is 7x7 Now I can use ListDensityPlot with InterpolationOrder->1 to get 6x6 smooth heat map.

ListDensityPlot[Transpose@Partition[data2, 7], 
 ColorFunction -> "TemperatureMap", Mesh -> 5, Frame -> True, 
 InterpolationOrder -> 1, MeshStyle -> Black, FrameTicks -> False, 
 FrameLabel -> {"IPTG", "Rib"}, PlotLabel -> "Data Heat Map ", 
 PlotLegends -> 
  BarLegend[{"TemperatureMap", {1, 5}}, 
   LegendLabel -> 
    Placed["Fluorescence (MEPE)", Right, Rotate[#, 90 Degree] &], 
   LegendMarkerSize -> 170], ImageSize -> 200]

Which is what I want..

Inspared by http://stackoverflow.com/questions/31063591/in-matlab-how-to-smooth-pixels-in-2d-heatmap-using-imagesc

POSTED BY: Okkes Dulgerci

O btw, the reason why ListDensityPlot 'does not work' is because values in ListDensityPlot are at the edges of the squares. The color of the squares are based on the value of n-th order interpolation between points, so it will be size-1.

POSTED BY: Sander Huisman
Posted 9 years ago
POSTED BY: Okkes Dulgerci

I'm not sure if i understand you... How can you interpolate 6 values to get 6 values, you will get 5 right? You will have 6 data-points and you want to create new ones in between; that is what 'inter' really means no? Or you could combine interpolated values and original values in some way...

if you want to have a color-gradients, then you need ListDensityPlot. So for 2 x 2 points it will create a single square blending the color in between based on the InterpolationOrder. So for n x n you will get n-1 x n-1 necessarily... I can't imagine n x n points creating a smoothed plot on an n x n grid, for n*n points there are necessarily n-1 x n-1 grid-cells to interpolate over?

POSTED BY: Sander Huisman
Posted 9 years ago

Oh, I see now. I guess what I want is not possible. Thanks for your suggestions.

POSTED BY: Okkes Dulgerci

You could try MatrixPlot:

MatrixPlot[Partition[data, 6], Mesh -> 5, PlotRange -> All, 
 ColorFunction -> "TemperatureMap", PlotLegends -> Automatic, 
 FrameLabel -> {"IPTG", "Rib"}, 
 PlotLabel -> "Model Prediction Heat Map", DataReversed -> True]

edit, somehow ColorFunctionScaling does not work properly for me, but can be fixed like this:

{min, max} = MinMax[data]
MatrixPlot[Partition[data, 6], PlotRange -> All, 
 ColorFunction -> (ColorData["TemperatureMap"][(#1 - min)/(max - min)] &), 
 PlotLegends -> Automatic, FrameLabel -> {"IPTG", "Rib"}, 
 PlotLabel -> "Model Prediction Heat Map", DataReversed -> True, 
 ColorFunctionScaling -> False]
POSTED BY: Sander Huisman
Posted 9 years ago

Thanks Sander, that works but I realize color of ArrayPlot is more suitable. Thanks again..

ArrayPlot[Transpose@Partition[data, 6], Mesh -> 5, PlotRange -> All, 
 ColorFunction -> "TemperatureMap", PlotLegends -> Automatic, 
 FrameLabel -> {"IPTG", "Rib"}, 
 PlotLabel -> "Model Prediction Heat Map", DataReversed -> True, 
 MeshStyle -> Black]
POSTED BY: Okkes Dulgerci

Yeah, ArrayPlot also works, those functions are nearly identical. ArrayPlot does not do interpolations for large amount of data, is generally faster, but not good for sparse arrays apparently. See e.g.: http://mathematica.stackexchange.com/questions/9428/what-is-the-fundamental-difference-between-arrayplot-and-matrixplot

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard