Message Boards Message Boards

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

Smooth heat map using ListDensityPlot of data in 6x6?

Posted 8 years ago

Hi All, Assume I have the following data and I want to plot heat map of it. Why I am not getting 6 squares for each row and for each column but getting 5 squares for each rows and columns? Any suggestion. Thanks in advanve.

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};

ListDensityPlot[Partition[data, 6], InterpolationOrder -> 0, 
 Mesh -> 4, PlotRange -> All, ColorFunction -> "TemperatureMap", 
 PlotLegends -> Automatic, FrameLabel -> {"IPTG", "Rib"}, 
 PlotLabel -> "Model Prediction Heat Map"]

But what I want is this

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

Of course, for each mesh square should have unique heat color.. They are not match as you can see, it match for the first one but it is not 6x6..

Is it by default MMA gives always 5x5 ListDensityPlot when you have 6x6 data? enter image description here

I would like to get this kind of heat map if possible. I believe this pic produced using MatLab using the same data (possible transpose of data). Note that it is 6x6 squares not 5x5..

Thanks..

POSTED BY: Okkes Dulgerci
8 Replies

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 8 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

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 8 years ago

Thanks Sander for your help. Now I face one minor problem. These two function does not have InterpolationOrder->1 option. Can I still smoot the data using one of the function (MatrixPlot, ArrayPlot) like it does ListDensityPlot[data,InterpolationOrder->1]. I mean I need two differen heat plot:

1)

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]

Or your edited version.

2)

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

Otherwise I need to think about ListDensityPlot,but I don't know how to fix 6x6 issue.

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 8 years ago

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

POSTED BY: Okkes Dulgerci
Posted 8 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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract