0
$\begingroup$

This is kinda a follow up to a previous plot where I was trying to visualize a 4D data, T(x,y,z,t) (3D space and time of temperature). SliceContourPlot3D. I wanted to move away from evaluating the function every time because in the real application my function will have 100s of elements. So I wanted to create a data table and use ListSliceContourPlot3D. However,

  1. Data evaluation to a table is really slow the way I coded. I know that there should be a faster way but I am not sure how. (Solution is in the update)
  2. The user can click on the + sign on the right of the slider and enter any value and receives a plot. However, the data is evaluated at 0.1 intervals (in this case) so you don't have access to 2.22. You have access to 2.2 and 2.3. How can I avoid user entering such values? Also what does Mathematica plots when I enter 2.33 for all the variables? Is Mathematica doing an interpolation?

This is the first version (thanks to @kglr):

g[x_, y_, z_, t_] := 
Sin[x] Cos[y] Sin[z] Exp[
t];

data = N[Table[
g[x, y, z, t], {x, 0, 10, 0.1}, {y, 0, 10, 0.1}, {z, 0, 10, 0.1}]];

Manipulate[
If[planes === {}, planes = {"XStackedPlanes"}];
data2 = data /. N[t] -> tijk;

ListSliceContourPlot3D[data2, 
planes /. {"XStackedPlanes" -> {"XStackedPlanes", {i}}, 
"YStackedPlanes" -> {"YStackedPlanes", {j}}, 
"ZStackedPlanes" -> {"ZStackedPlanes", {k}}}, 
DataRange -> {{0, 10}, {0, 10}, {0, 10}}, 
AxesLabel -> {Style["x", 13, Blue], Style["y", 13, Blue], 
Style["z", 13, Blue]}, PlotLegends -> Automatic, 
ColorFunction -> "TemperatureMap", 
PerformanceGoal -> "Quality"], {{planes, "XStackedPlanes", 
Style["Planes of Interest", 12, Blue]}, {"XStackedPlanes", 
"YStackedPlanes", "ZStackedPlanes"}, 
TogglerBar}, {{tijk, 0, Style["Time", 12, Blue]}, 0, 10, 1, 
Appearance -> "Labeled"}, {{i, 0, 
Style["zy plane position", 12, Blue]}, 0, 10, 0.1, 
Appearance -> "Labeled", 
Enabled -> MemberQ[planes, "XStackedPlanes"]}, {{j, 0, 
Style["zx plane position", 12, Blue]}, 0, 10, 0.1, 
Appearance -> "Labeled", 
Enabled -> MemberQ[planes, "YStackedPlanes"]}, {{k, 0, 
Style["xy plane position", 12, Blue]}, 0, 10, 0.1, 
Appearance -> "Labeled", 
Enabled -> MemberQ[planes, "ZStackedPlanes"]}, 
ContinuousAction -> False]

It works but there is room to make it better.

UPDATE: I found the way to make the 4D table really fast

g[x_, y_, z_, t_] := Sin[x] Cos[y] Sin[z] Exp[t];
AbsoluteTiming[
data = Table[
Evaluate@N[g[x, y, z, t]], {x, 0, 10., 0.1}, {y, 0, 10., 0.1}, {z,
  0, 10., 0.1}, {t, 0, 10., 0.1}];]

And to pick up the right location simply data[[i,All,All,All]];

$\endgroup$
  • 1
    $\begingroup$ Where is the question in this post? And if you're answering a question you think is worth sharing you should still post the solution as an answer to your own question instead of using the question as a blog post. $\endgroup$ – Thies Heidecke Nov 22 '18 at 13:16
  • $\begingroup$ @ThiesHeidecke It is not a complete answer. I am trying to figure the 1st one still. If I can, I will post as a whole answer. $\endgroup$ – Erdem Nov 22 '18 at 13:18
  • $\begingroup$ Ok, it's probably still a good idea to start with the question part to avoid confusion of readers and possible downvotes or close votes. $\endgroup$ – Thies Heidecke Nov 22 '18 at 13:19
  • $\begingroup$ @ThiesHeidecke I edited the question. $\endgroup$ – Erdem Nov 22 '18 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.