# How to add FindDivisions to the plot commands?

I used these instructions to make a legend bar next to my plot (I can't comment there)

But I'm lost to where and how can I add FindDivisions to the DensityPlot under "Edit: illustrating additional options"?

{densityPlot, densityColors, densityRange} =
reportColorRange[
ListStreamDensityPlot[data, VectorScale -> Small,
DataRange -> {{0, 2 Pi}, {-0.5, 0.5}},
ColorFunction -> ColorData["Rainbow"]]];

With[{plotWidth = .85, aspectRatio = .9},
density =
display[{densityPlot // at[{0, 0}, plotWidth],
colorLegend[densityColors, densityRange, LabelStyle -> LightGray,
FrameStyle -> Orange, "ColorBarFrameStyle" -> LightGray,
Background -> Darker@Darker@Darker@Blue, "ColorSwathes" -> None,
Contours -> 10, RoundingRadius -> 0, BoxFrame -> 3,
"Digits" -> 2] //
at[{plotWidth, 0}, {1 - plotWidth, plotWidth/aspectRatio}]},
AspectRatio -> aspectRatio, ImageSize -> 400]]


Also how can I add another plot to the existing one? I would need to draw a sinusoid on it. Show command ruins it. It's obvious where sinusoid should be.

This is my plot:

I would like my numbers in a bar legend rounded.

Thanks in advance.

P.S. Just in case you need data I used for my plot.

a = 0.05
z = -1
data =
Table[With[{x = 0 + 2 Pi/5 (i - 1),
y = -0.5 + 0.2 (j - 1)}, {{NIntegrate[
a*z*Cos[t]/((t^2 - 2 t x + x^2 + y^2 + z^2)^(3/2) -
3 (y Sqrt[t^2 - 2 t x + x^2 + y^2 + z^2] Sin[
t]) a), {t, -Infinity, Infinity},
Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 800,
Method -> "GaussKronrodRule"}, AccuracyGoal -> 20,
MaxRecursion -> 20],
NIntegrate[-z/((t^2 - 2 t x + x^2 + y^2 + z^2)^(3/2) -
3 (y Sqrt[t^2 - 2 t x + x^2 + y^2 + z^2] Sin[
t]) a), {t, -Infinity, Infinity},
Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 800,
Method -> "GaussKronrodRule"}, AccuracyGoal -> 20,
MaxRecursion -> 20]},
NIntegrate[(y +
a*(t*Cos[t] - x*Cos[t] - Sin[t]))/((t^2 - 2 t x + x^2 + y^2 +
z^2)^(3/2) -
3 (y Sqrt[t^2 - 2 t x + x^2 + y^2 + z^2] Sin[
t]) a), {t, -Infinity, Infinity},
Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 800,
Method -> "GaussKronrodRule"}, AccuracyGoal -> 20,
MaxRecursion -> 40]}], {i, 1, 6}, {j, 1, 6}]

• several questions here use FindDivisions. Also, a possible dupe of: mathematica.stackexchange.com/q/6108/5
– rm -rf
Sep 25, 2012 at 23:18
• I have checked those threads but I'm still lost where to put FindDivisions in the code above? Sep 25, 2012 at 23:34

## 1 Answer

It is buried deep in Jens' code but if you add the option

Contours -> 1. FindDivisions[densityRange, 10]


to your display function you'll get a better scale. I used 1. here because I otherwise got fractions as scale ticks.

You write you prefer 'rounded' numbers with specifying what that should mean. Normally that would imply you end up with integer values, but with the range in your example that can't be what you want. FindDivisions offers the capability to set the desired increments yourself. In this case, for instance with 0.25 sized increments you'd need to write:

Contours -> FindDivisions[AppendTo[densityRange, .25], 10]


As to the adding the sine plot: do it after Jens' code has extracted the necessary information, so in the final displaystage:

With[{plotWidth = .85, aspectRatio = .9},
density =
display[
{
(*==>*)Show[densityPlot, Plot[.3 Sin[x], {x, 0, 2 \[Pi]}]] // t[{0, 0}, plotWidth],
colorLegend[densityColors, densityRange,
Contours -> FindDivisions[AppendTo[densityRange, .25], 10],
LabelStyle -> LightGray, FrameStyle -> Orange,
"ColorBarFrameStyle" -> LightGray,
Background -> Darker@Darker@Darker@Blue, "ColorSwathes" -> None,
Contours -> 10, RoundingRadius -> 0, BoxFrame -> 3,
"Digits" -> 2] //
at[{plotWidth, 0}, {1 - plotWidth, plotWidth/aspectRatio}]},
AspectRatio -> aspectRatio, ImageSize -> 400]]


• Thanks you very much. This was most helpful. Sep 26, 2012 at 16:15