How to get Plot to use a specific ImageSize in 3D when using the mouse to rotate an image

(Mathematica version: 8.0.4, on Windows 7)

Can someone please remind me how to tell M not to change ImageSize in the following case:

I have Manipulate where I make a grid, and inside the grid I either show one graph or 2 graphs, depending on the choice of the control.

So that the overall image is displayed the same way, then if I show one graph, I use the same size, and if I show 2 graphs, I use half the length for each plot. Pretty easy.

The strange thing is that when I use the mouse to rotate one plot case, and then switch back to 2 graphs, the graph size now does not use the ImageSize I specified.

It seems that using the mouse to rotate one chart, this affected the next chart, shown in the same place on the screen.

Using SphericalRegion -> True or not has no effect. Using RotationAction -> "Fit" has no effect.

Here is a small example of what I mean, and then I will show how I am now solving this problem. But I solve this using GraphicsGrid instead of Grid. I wanted to continue using the Grid, if possible.

 Manipulate[ Module[{opt = {Spacings -> {0, 0}, Frame -> All}, p, size, data = Table[RandomReal[], {10}, {10}], wid = 300, len = 300}, size = If[choice == 1, {wid, len}, {wid, len/2}]; Print[size]; p = ListPlot3D[data,SphericalRegion->True,ImagePadding -> 10,ImageSize ->size]; If[choice == 1, Grid[{{p}}, Sequence@opt ], Grid[{{p}, {p}}, Sequence@opt ] ] ], Row[{SetterBar[Dynamic[choice], {1, 2}]}], {{choice, 2}, None} ] 

To reproduce the problem is simple: first I mark the size, this is how I want to save it. Now I click on choice 1, now with the mouse I rotate one plot. Now I click on selection 2 to go back, then I see that the plot size is not what I expected.

enter image description here

I am sure this is the option I need to use. Just haven't found it yet.

ps. In fact, what seems to be happening is that the TOM THEME that was rotated remains on the content area and was used instead of one of the two graphs in the second case. Very strange. I have to do something stupid, because it's too weird.

Update 2:48 AM This is a response to using Dynamic in a Manipulate expression, as shown below by MrWizard. On V 8.04 it does not work. Here is the code:

 Manipulate[ Module[{p, size, data = Table[RandomReal[], {10}, {10}], wid = 300, len = 300}, size = If[choice == 1, {wid, len}, {wid, len/2}]; p = ListPlot3D[data, SphericalRegion -> True, ImagePadding -> 10, ImageSize -> size]; If[choice == 1, Grid[{{p}}], Dynamic@Grid [{{p}, {p}}] ] ], Row[{SetterBar[Dynamic[choice], {1, 2}]}], {{choice, 2}, None} ] 

enter image description here

Update 3:03 AM

This below works by saving the grid. Adding a frame around the grid makes it work. (Thanks to Mike's answer showing that using Frame instead of Grid made it work, I decided to let me try creating a frame around the grid)

One of the strangest things I've seen with Mathematica for a long time :)

 Manipulate[ Module[{p, size, data = Table[RandomReal[], {10}, {10}], wid = 300, len = 300}, size = If[choice == 1, {wid, len}, {wid, len/2}]; p = ListPlot3D[data, SphericalRegion -> True, ImagePadding -> 10, ImageSize -> size]; If[choice == 1, Framed@Grid [{{p}}], Grid[{{p}, {p}}] ] ], Row[{SetterBar[Dynamic[choice], {1, 2}]}], {{choice, 2}, None} ] 

thanks

+6
source share
3 answers

This is due to another mystery, like // why Plot3D remembers image parameters why Plot3D remembers .... In this case, the solution will be the same: add PreserveImageOptions -> False as an option in Plot3D . One way or another, hacks like those suggested by MrW and Mike made Plot3D β€œforget”.

+5
source

I didn't have much time, but using the Grid seems to be the main thing that messed it up, although I didn't have time to determine how / why. If you replace the If statement as follows:

 If[choice == 1, Framed@p , Grid[{{p}, {p}}, Sequence@opt ]] 

then it works great. There are some other things in the code that at first glance do not seem optimal, but I just focused on the size of the graphics due to time limitations. This is not intended as an explanation, but may help you or someone else to understand why this is behaving this way. Sorry, but a short time, but I thought it was worth publishing an observation of the Grid .

+2
source

Without any actual analysis, here is my hypothesis.

I believe that this may be the result of an optimization method that notes that the visible content of the displayed graphics has not changed. I believe that the key is to make the apparent content different between each graphic displayed at each grid position. Using something like Identity will not work as it disappears from the expression. However, if this assumption is correct, I expect that any constant change will lead to an update of the schedule.

I had success using each of them for the first Grid expression:

Grid[{{ Framed@p }}, opt]

Grid[{{ Panel@p }}, opt]

Grid[{{ Pane@p }}, opt]

Grid[{{ {p} }}, opt]

Grid[{{ Item@p }}, opt]

Grid[{{ Style@p }}, opt]

+1
source

Source: https://habr.com/ru/post/904516/


All Articles