0
$\begingroup$

I have a list of experimental (x,y,f) data, e.g. I can generate similar data with this:

Fitness[{x_, y_}] := (x - 1)^2 + 10 (x^2 - y)^2;
ListDensityPlot[Flatten[#, 1] &@ Table[{x, y, Fitness[{x, y}]}, {x, -1, 1.5, 0.1}, {y, -1, 1.5, 
    0.1}], InterpolationOrder -> 0]

enter image description here

How to show more range in this ListDensityPlot to illustrate absence of data (of course with white backgroung style)? I mean that if you just try to increase range with PlotRange -> {{-5, 5}, Automatic, Automatic}, you will see smth like this enter image description here

This picture illustrates that WM instead of showing white background in regions without data interpolates data or, idk, tries to copy extreme values of data and shows this values in no data regions.

How to show white background in regions where I don't have experimental data?

$\endgroup$
1
  • 1
    $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Commented Jul 27, 2021 at 14:51

2 Answers 2

0
$\begingroup$

You can use RegionFunction to limit where the data is plotted. For example, to plot just for x values between -1 and 1.5:

ListDensityPlot[Flatten[#, 1] &@
   Table[{x, y, Fitness[{x, y}]}, {x, -1, 1.5, 0.1}, {y, -1, 1.5, 
0.1}], InterpolationOrder -> 0, 
 PlotRange -> {{-5, 5}, Automatic, Automatic}, 
 RegionFunction -> Function[{x, y, f}, -1 <= x <= 1.5]]

enter image description here

If you want the full range of your function for x from -1 to 1.5, change the PlotRange to {{-5, 5}, Automatic, All}

$\endgroup$
1
  • $\begingroup$ Thank you! This is the best way! $\endgroup$ Commented Jul 28, 2021 at 10:10
0
$\begingroup$

I think the easiest way would be to use PlotPaddingRange inside Show just like this:

Show[ListDensityPlot[
  Flatten[#, 1] &@
   Table[{x, y, Fitness[{x, y}]}, {x, -1, 1.5, 0.1}, {y, -1, 1.5, 
     0.1}], InterpolationOrder -> 0],
 PlotRangePadding -> {{4, 3.5}, {0, 0}}]

And the result (please, do not mind small white artifacts) would be: -5_5

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.