Question

I am trying to plot a series of data corresponding to (x,y) positions using ListDensityPlot in Mathematica 7. mydata is a list of data triplets {x,y,f}, where f is a real number between -4.5 and +4.5 (inclusive).

I would like ListDensityPlot to have deep blue color when f=-4.5 and deep red color when f=+4.5, and color that is linearly interpolated between blue and red when f is between -4.5 and +4.5.

I have tried to use a command like:

Show[{
  ListDensityPlot[mydata, FrameLabel -> {"x", "y"}, 
   ColorFunction -> (Blend[{{-4.5, Blue}, {4.5, Red}}, #] &), 
   ImageSize -> 500],
  Graphics[
   Map[Text[ToString[Round[#[[4]], 0.1]], #[[1 ;; 2]]] &, data]
   ]
  }]

I get the following:

ListDensityPlot of mydata

I have pasted mydata below. ListDensityPlot generates a plot, but strangely, regions of very negative f have been colored white, not blue as they should be. Do you have any ideas about how I can fix this?

mydata={{0.0706972,0.0612815,0.156232},
{0.353737,0.0612826,0.362632},
{0.495237,0.0612793,0.305966},
{0.778237,0.0612736,0.205575},
{0.919737,0.0612732,0.305138},
{1.34424,0.0612733,0.9149},
{1.62724,0.0612745,-0.0153983},
{1.76874,0.0612779,-0.0400239},
{2.05173,0.061282,0.0968682},
{2.19323,0.061269,0.24809},
{2.47623,0.0612574,0.830854},
{2.61773,0.0612641,0.792518},
{2.90075,0.0612581,0.627821},
{3.04225,0.0612652,0.914969},
{0.141468,0.183812,0.409818},
{0.282968,0.183814,0.768611},
{0.565988,0.183822,0.384961},
{0.707488,0.183816,0.17869},
{0.990485,0.183817,0.143558},
{1.41499,0.183815,0.105034},
{1.55649,0.183821,-0.124248},
{1.83948,0.183824,-0.0827487},
{1.98098,0.183826,0.0105883},
{2.26399,0.183803,0.337229},
{2.40549,0.183806,1.28208},
{2.68849,0.1838,0.949262},
{2.82999,0.183793,0.706267},
{3.113,0.18381,1.94937},
{0.07072,0.306355,0.287076},
{0.35373,0.30635,1.89559},
{0.49523,0.30636,0.880476},
{0.778235,0.306361,0.0173677},
{0.919735,0.30636,-0.166621},
{1.20273,0.306355,0.150628},
{1.34423,0.306353,-0.0607556},
{1.62724,0.306367,-0.318956},
{1.76874,0.30637,-0.145211},
{2.05175,0.306357,0.0208272},
{2.19325,0.30635,-0.0423171},
{2.61774,0.306343,1.56449},
{2.90073,0.306342,0.674011},
{3.04223,0.306341,0.953657},
{3.32522,0.306381,1.1894},
{0.141477,0.428894,0.618096},
{0.565987,0.428899,0.6901},
{0.707487,0.428905,0.106956},
{0.990492,0.428898,-0.0971399},
{1.13199,0.428902,0.00726246},
{1.41498,0.428898,-0.00873916},
{1.55648,0.428906,0.105947},
{1.83949,0.428908,0.766284},
{1.98099,0.428897,0.316873},
{2.264,0.428892,-0.00432865},
{2.68849,0.428889,0.67258},
{2.82999,0.428887,0.526888},
{3.11296,0.428893,0.628485},
{3.25447,0.428921,0.573774},
{0.0707381,0.551442,-0.14735},
{0.495233,0.551439,1.1216},
{0.778241,0.551445,-0.0890709},
{0.91974,0.55144,0.33001},
{1.20273,0.551448,0.563503},
{1.34423,0.551443,0.404971},
{2.05174,0.551439,0.367543},
{2.19324,0.551431,-0.0455066},
{2.47624,0.551445,0.35311},
{2.61774,0.551434,0.311075},
{2.90073,0.551435,0.3781},
{3.04223,0.551442,0.381492},
{3.32524,0.55145,0.277341},
{0.141493,0.673982,-0.145419},
{0.282993,0.673978,0.42935},
{0.565985,0.67398,0.256423},
{0.707485,0.673984,-0.000328871},
{1.13198,0.67399,1.95841},
{1.41498,0.673988,0.867256},
{1.55648,0.673977,1.69639},
{1.8395,0.673988,2.00345},
{1.981,0.673983,0.856412},
{2.26399,0.673977,-0.00904543},
{2.40549,0.673987,-0.0313169},
{2.68848,0.673979,0.216407},
{2.82998,0.673982,0.29249},
{3.11298,0.673982,0.272341},
{3.25448,0.673988,0.208162},
{0.0707369,0.796521,-0.0698865},
{0.353738,0.796524,0.200232},
{0.495237,0.796524,0.195742},
{0.778236,0.796526,0.531634},
{1.20273,0.796532,1.62237},
{1.34423,0.796532,1.03682},
{1.62724,0.796515,1.4727},
{1.76874,0.796526,1.51058},
{2.05174,0.796529,0.547837},
{2.19324,0.796521,0.197249},
{2.47624,0.79653,0.0709165},
{2.61774,0.796525,0.171138},
{2.90073,0.796525,0.322391},
{3.04223,0.796526,0.292232},
{3.32524,0.796526,0.112837},
{0.14148,0.919067,0.164426},
{0.28298,0.919062,0.352007},
{0.565982,0.91907,0.227861},
{0.707482,0.919067,0.223424},
{0.990472,0.919081,1.51778},
{1.13197,0.919068,1.43614},
{1.41499,0.91907,0.928125},
{1.55649,0.919058,1.02439},
{1.83949,0.919069,1.29591},
{1.98099,0.919072,0.889546},
{2.26399,0.919065,0.160443},
{2.40549,0.919072,0.118355},
{2.68848,0.91907,0.304887},
{2.82998,0.919068,0.419197},
{3.11299,0.919065,0.297583},
{3.25449,0.919069,0.112569},
{0.0707326,1.04161,0.271365},
{0.353732,1.0416,1.35402},
{0.495232,1.04161,0.73555},
{0.778227,1.04161,0.266921},
{0.919727,1.04163,0.558285},
{1.20274,1.0416,0.990328},
{1.34424,1.04161,0.853826},
{1.62723,1.04161,1.04307},
{1.76873,1.04161,1.8516},
{2.05174,1.04162,1.03597},
{2.19324,1.04161,0.286579},
{2.47623,1.04162,0.192482},
{2.61773,1.04161,0.327713},
{2.90072,1.04162,0.75709},
{3.04222,1.0416,0.671078},
{3.32523,1.04162,-0.0649734},
{0.141487,1.16415,0.674372},
{0.565979,1.16416,0.382277},
{0.707479,1.16416,0.130031},
{0.990489,1.16416,0.359462},
{1.13199,1.16414,0.878039},
{1.41498,1.16416,0.61436},
{1.55648,1.16415,0.689871},
{2.26398,1.16415,0.192415},
{2.40548,1.16416,0.170731},
{2.68848,1.16416,0.542642},
{2.82998,1.16417,1.02121},
{3.11298,1.16413,0.922837},
{3.25448,1.16416,-0.179699},
{0.0707247,1.28669,0.0677972},
{0.495222,1.28669,0.499906},
{0.778234,1.2867,0.0477497},
{0.919734,1.2867,0.124899},
{1.34422,1.2867,0.521025},
{1.62723,1.28669,0.575308},
{1.76873,1.28669,1.32615},
{2.05174,1.2867,1.37879},
{2.19324,1.2867,0.30413},
{2.47624,1.2867,0.211985},
{2.61774,1.2867,0.407686},
{2.90075,1.2867,1.85405},
{3.32522,1.2867,-0.534791},
{0.141484,1.40922,-0.175515},
{0.282984,1.40925,0.108059},
{0.565982,1.40923,-0.103901},
{0.707482,1.40924,-0.0534677},
{0.990496,1.40924,0.457061},
{1.41498,1.40923,-0.00897326},
{1.55648,1.40924,0.177633},
{1.83948,1.40923,0.627124},
{1.98098,1.40924,0.705649},
{2.26399,1.40924,0.0823105},
{2.40549,1.40924,0.118441},
{2.68849,1.40924,0.463805},
{2.82999,1.40924,0.807462},
{3.25446,1.40924,-0.334339},
{0.0707259,1.53176,0.303614},
{0.353736,1.53179,-0.456059},
{0.495236,1.53178,-0.30149},
{0.778233,1.53178,-0.00087831},
{0.919733,1.53177,0.13351},
{1.20273,1.5318,0.264503},
{1.34423,1.53178,-0.11381},
{1.62723,1.53178,0.135977},
{1.76873,1.53178,0.189756},
{2.05173,1.53178,0.0612269},
{2.19323,1.53177,-0.0207708},
{2.47623,1.53179,0.157959},
{2.61773,1.53178,0.280563},
{2.90074,1.53178,0.416675},
{3.04224,1.53181,0.455576},
{3.32523,1.53177,-0.39161},
{0.28297,1.65433,-0.417088},
{0.565986,1.65432,-0.196449},
{0.707486,1.65432,0.00604892},
{0.990476,1.65432,0.106779},
{1.13198,1.65434,0.0467161},
{1.41498,1.65432,0.0226911},
{1.55648,1.65432,0.144174},
{1.83949,1.65431,0.0504401},
{1.98099,1.65433,-0.0920306},
{2.26398,1.65431,0.237136},
{2.40548,1.65433,0.206919},
{2.68848,1.65433,0.277651},
{2.82998,1.65432,0.234855},
{3.11299,1.65435,-0.0697331},
{3.25449,1.65432,-0.237554},
{0.35373,1.77686,-0.428184},
{0.49523,1.77686,-0.201981},
{0.778235,1.77687,0.281973},
{0.919735,1.77687,0.21639},
{1.20274,1.77687,-0.0273937},
{1.34424,1.77687,0.0617077},
{1.62724,1.77686,0.446966},
{1.76874,1.77686,0.232278},
{2.05175,1.77687,-0.00366157},
{2.47623,1.77687,0.590334},
{2.61773,1.77687,0.366771},
{2.90072,1.77687,0.144399},
{3.04222,1.77688,0.0118864},
{3.32523,1.77687,-0.173756},
{0.14148,1.8994,1.02011},
{0.28298,1.8994,-0.061488},
{0.565979,1.8994,0.17958},
{0.707479,1.89941,0.835386},
{0.990494,1.8994,0.440723},
{1.13199,1.89942,-0.0329292},
{1.415,1.89941,0.366622},
{1.5565,1.8994,1.28723},
{1.83948,1.8994,0.293736},
{1.98098,1.8994,0.00525588},
{2.40546,1.89941,1.61209},
{2.68847,1.89941,0.349228},
{2.82997,1.89941,0.22748},
{3.11299,1.89942,-0.00597278},
{3.25449,1.89941,-0.092036},
{0.0707248,2.02194,0.636689},
{0.353732,2.02195,-0.058178},
{0.495232,2.02194,0.0810127},
{1.20274,2.02196,-0.140002},
{1.34424,2.02195,0.0609502},
{1.76874,2.02195,1.1271},
{2.05174,2.02194,0.317189},
{2.19324,2.02198,1.20302},
{2.47623,2.02194,0.845124},
{2.61773,2.02196,0.433377},
{2.90076,2.02192,0.26099},
{3.04226,2.02197,0.106698},
{3.32522,2.02196,-0.0906011},
{0.141485,2.14448,0.374416},
{0.282984,2.14449,0.0356299},
{0.565983,2.14449,0.144408},
{0.707483,2.14449,0.471678},
{0.990483,2.14449,-0.148388},
{1.13198,2.1445,-0.218279},
{1.41499,2.14449,0.573905},
{1.83948,2.14449,0.604341},
{1.98098,2.14448,0.294743},
{2.264,2.14452,0.728224},
{2.4055,2.1445,0.665019},
{2.68848,2.14451,0.227231},
{2.82998,2.14445,0.50959},
{3.11298,2.14453,0.00769447},
{3.25448,2.14451,-0.0936787},
{0.0707435,2.26703,1.27544},
{0.353741,2.26703,0.401916},
{0.495241,2.26703,0.00138117},
{0.778236,2.26703,0.0826728},
{0.919736,2.26703,-0.0942034},
{1.20274,2.26704,-0.0863266},
{1.34424,2.26704,0.0960122},
{1.62724,2.26704,1.72132},
{1.76874,2.26703,0.764364},
{2.05172,2.26703,0.224997},
{2.19322,2.26705,0.361237},
{2.47625,2.26704,0.330025},
{2.61775,2.26706,0.168311},
{3.04219,2.26705,0.123366},
{3.32524,2.26705,-0.138312},
{0.565992,2.38958,-0.061663},
{0.707492,2.38957,0.604119},
{0.990481,2.38958,0.372093},
{1.13198,2.38958,0.101297},
{1.41498,2.38958,0.188174},
{1.55648,2.38958,0.458169},
{1.83948,2.38958,0.0724903},
{1.98098,2.38958,0.0125407},
{2.26399,2.38958,0.286051},
{2.40549,2.38958,0.27231},
{2.68854,2.38958,0.422585},
{3.11298,2.38957,-0.328397},
{3.25448,2.38958,-0.231746},
{0.0707321,2.51211,1.44201},
{0.353741,2.51212,0.997955},
{0.495241,2.51212,-0.097323},
{0.919736,2.51212,1.16621},
{1.20273,2.51212,0.135307},
{1.34423,2.51212,0.0884575},
{1.62723,2.51212,0.199534},
{1.76873,2.51212,0.284312},
{2.05174,2.51212,0.376083},
{2.19324,2.51212,0.301128},
{2.47624,2.51212,0.215957},
{2.61774,2.51209,0.217169},
{2.90075,2.51218,0.204606},
{3.04225,2.51212,-0.343601},
{3.32523,2.51212,-0.207826},
{0.14149,2.63464,0.760709},
{0.28299,2.63466,0.636106},
{0.565986,2.63466,-0.200649},
{0.990483,2.63467,0.38127},
{1.13198,2.63466,0.180752},
{1.41498,2.63467,0.080896},
{1.55648,2.63466,0.131224},
{2.26399,2.63466,0.318763},
{2.40549,2.63466,0.232494},
{2.68845,2.63466,0.173288},
{2.82995,2.6347,0.0815537},
{3.11299,2.63467,-0.417195},
{3.25449,2.63467,-0.360641},
{0.0707531,2.75719,0.400114},
{0.353738,2.7572,0.0819705},
{0.495238,2.75721,-0.302042},
{0.77823,2.75721,-0.0608161},
{0.91973,2.75721,-0.0220837},
{1.20273,2.75721,0.0548718},
{1.34423,2.75721,0.0526273},
{1.62723,2.7572,0.187936},
{1.76873,2.7572,0.531338},
{2.05175,2.7572,0.709803},
{2.19325,2.75721,0.396736},
{2.47623,2.75721,0.210757},
{2.61773,2.75722,0.190273},
{2.90074,2.75722,0.0844574},
{3.04224,2.75721,0.138748},
{3.32525,2.75721,0.160425},
{0.14149,2.87974,0.363203},
{0.28299,2.87975,0.244034},
{0.565983,2.87975,-0.409196},
{0.707483,2.87975,-0.416919},
{0.99048,2.87975,-0.115925},
{1.13198,2.87975,-0.0307684},
{1.41498,2.87975,0.0458043},
{1.55648,2.87975,0.118416},
{1.83948,2.87974,0.518182},
{1.98098,2.87973,0.709087},
{2.26399,2.87976,0.300235},
{2.40549,2.87975,0.230943},
{2.68848,2.87976,0.269828},
{2.82998,2.87976,0.305987},
{0.0707505,3.00229,0.393115},
{0.353735,3.00229,0.400262},
{0.495235,3.0023,-0.338383},
{0.778234,3.00229,-0.349416},
{0.919734,3.00229,-0.222599},
{1.20273,3.00229,-0.0503835},
{1.34423,3.00229,-0.000876455},
{1.62723,3.00229,0.197986},
{1.76873,3.00228,0.612382},
{2.05173,3.00227,1.57516},
{2.19323,3.0023,0.482992},
{2.47623,3.0023,0.264858},
{2.61773,3.0023,0.374041},
{2.90073,3.0023,0.630716},
{3.04223,3.00228,0.969562},
{3.32525,3.00228,0.694023},
{0.141493,3.12484,0.767782},
{0.565987,3.12484,-0.426869},
{0.707487,3.12484,-0.36955},
{0.990482,3.12484,-0.171065},
{1.13198,3.12483,-0.0992636},
{1.41498,3.12483,0.00664908},
{1.55648,3.12484,0.0897731},
{1.83947,3.12483,1.42719},
{2.26396,3.12485,0.458249},
{2.40546,3.12483,0.304871},
{2.68848,3.12484,0.801844},
{2.82998,3.12485,1.08225},
{3.11299,3.12482,0.735036},
{3.25449,3.12482,0.543969},
{0.0707704,3.2474,0.337828},
{0.495241,3.24738,0.0492609},
{0.778239,3.24738,-0.266473},
{0.919739,3.24738,-0.191448},
{1.20273,3.24737,-0.0773949},
{1.34423,3.24738,-0.0336819},
{1.62723,3.24738,0.104047},
{1.76873,3.24738,0.35747},
{2.1932,3.24738,1.35879},
{2.47622,3.24737,0.423317},
{2.61772,3.24738,1.0282},
{2.90075,3.24738,1.71781},
{3.04225,3.24737,0.920995},
{3.32527,3.24734,0.391254},
{0.141494,3.36996,0.398991},
{0.282994,3.36993,0.781157},
{0.565987,3.36993,-0.142879},
{0.707488,3.36992,-0.214649},
{0.990493,3.36992,-0.13519},
{1.13199,3.36992,-0.0936401},
{1.41499,3.36992,-0.0212588},
{1.55649,3.36992,0.0246321},
{1.83948,3.36992,0.392014},
{1.98098,3.36993,1.38817},
{2.26397,3.36991,0.686709},
{2.40547,3.36991,0.401295},
{3.113,3.36991,0.697915},
{3.2545,3.36987,0.410655},
{0.350533,0.545888,-3.34869},
{0.286178,0.434433,-3.12058},
{3.11939,2.87975,-3.85729},
{3.24809,2.87974,-3.97301},
{1.63364,0.551441,-2.89924},
{1.76234,0.551449,-2.45674},
{3.2577,0.17828,-2.21177},
{3.322,0.0667906,-2.87983},
{2.19645,1.78241,-3.95525},
{2.26076,1.89388,-2.79573},
{0.784635,2.02195,-3.4546},
{0.913335,2.02194,-3.7655},
{1.62404,2.02749,-2.66478},
{1.55969,2.13895,-2.61346},
{3.04545,1.29223,-2.72883},
{3.10976,1.40371,-3.71563},
{1.19954,0.0668163,-3.07412},
{1.13518,0.178269,-3.79084},
{2.4087,0.423353,-3.80006},
{2.47304,0.311891,-2.87613},
{2.83324,2.38408,-3.94676},
{2.89749,2.27256,-3.89199},
{0.0739331,1.77132,-2.43054},
{0.13827,1.65985,-3.79017},
{1.19952,1.29223,-3.81822},
{1.1352,1.40371,-3.82112},
{0.710686,2.62912,-4.17169},
{0.775036,2.51766,-3.21561},
{1.97458,1.16415,-2.66581},
{1.84588,1.16415,-2.24801},
{2.0485,3.24183,-2.45355},
{1.98417,3.13036,-2.41862},
{0.286188,1.16969,-3.49617},
{0.350522,1.28116,-3.46633},
{0.286193,3.13038,-3.37545},
{0.350541,3.24184,-3.61583},
{1.97459,2.63466,-3.70206},
{1.84589,2.63466,-3.88873},
{0.147892,2.38957,-2.94446},
{0.276592,2.38957,-3.06616},
{0.987283,0.679529,-2.82093},
{0.922936,0.790989,-3.25907},
{2.69488,3.36991,-2.91215},
{2.82358,3.36992,-2.66107}};

Thank you very much!

Andrew DeYoung Carnegie Mellon University

Was it helpful?

Solution

Setting PlotRange -> All in ListDensityPlot will include all values in the plot. You also need to set ColorFunctionScaling -> False to prevent the data fed into ColorFunction from being rescaled:

Show[{ListDensityPlot[mydata, FrameLabel -> {"x", "y"}, 
   ColorFunction -> (Blend[{{-4.5, Blue}, {4.5, Red}}, #] &), 
   ImageSize -> 500,
   ColorFunctionScaling -> False,
   PlotRange -> All], 
  Graphics[Map[Text[ToString[Round[#[[3]], 0.1]], #[[1 ;; 2]]] &, 
    mydata]]}]

Mathematica graphics

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top