How to get MATLAB zoom context menu "Reset to Original View" to work on a 3D plot? - matlab

I have several plots on one figure. One is a 3D plot, the rest are 2D. When I select Zoom on the toolbar, left clicking on the mouse uses the zoom.m functions, and in 3D, it looks like it uses camzoom.m. However, when I right click to bring up the context menu, the "Reset to Original View" looks like it only works on the 2D plots. For the 3D plot, selecting this either does nothing or it loses the x-axis limits, and therefore the plot shows no data points (I can't get it to work consistently).
I'm trying to come up with a workaround for this problem.
I would like to override the context menu for just the 3D plot with my own function that would redraw the plot, and leave the default context menu for the 2D plots. Is this possible? I'm thinking no, as there is only one zoom object for the entire figure, and MATLAB does not let me set the handle to the context menu while zoom is on.
Is there a way to get around this problem? It looks like an oversight on MATLAB's part to not have this function correctly!

Related

Can I make objects in a 3D Window clickable in AnyLogic?

I'm modeling some boxes with simple rectangles and I use the "on click" property to show information about its contents. However this only works for the 2D view, and I do need to have a 3D view where this functionality is also available because the boxes can be on top of each other.
I noticed that actual 3D objects do not have an "on click" property at all. Is it possible to make objects clickable in a 3D Window?
the only way you can click 3D objects is by adding some 2D element that is clickable on top of it, perhaps with transparent color, which will allow you to click the 3D object in a 2D animation.
Nevertheless in a 3D window, it's definitely not possible to interact with any object through mouse clicking
Nevertheless if you want to display information by clicking an object in 3D you can instead have a text object to display that information in 3D and you can make that object visible or not when you need.

Perspective control in MATLAB 3D figures

How to change the vanishing points (P1,P2,P3) in the perspective in MATLAB 3D figures?
Below there is a scheme of explanation what I mean:
Thanks in advance for your help.
If you want to control the perspective appearance in a plot, you'll want to first change the Projection property of the axes to perspective. Then you can change the various camera properties of the axes to get the view you want. The important ones for adjusting how the perspective looks are the CameraViewAngle and CameraPosition.
I have found that a "realistic" perspective view can be achieved using a CameraViewAngle of about 30 degrees, mimicking the preferred viewing area of the human eye:
The default CameraViewAngle is about 6.6, so setting it to 30 will cause the view to appear zoomed-out. You will then want to change the CameraPosition so that it is closer to the CameraTarget, thus zooming the view back in. You can use a larger CameraViewAngle if you want a more exaggerated perspective (like a fisheye lens).

Customizing a 3D Plotly Visualization with a slider bar

I've been exploring Plotly recently. I've made a contourslice of a 3D Value function using the Plotly MATLAB API's fig2plotly(). However, I've been researching how to further customize the plot, and I can't figure out how exactly I'd go about doing this.
My current plot is here:
https://plot.ly/~txizzle/81
It's basically different contours stacked on top of each other.
My goals:
I'd like to add a slider bar that will show just one contour slice at a time (maybe by changing visibility). Ideally, I could fix an eagle-eye view from the top, so moving the slider will make it appear as if the plot is 2D.
My thoughts on how to approach this:
1) https://plot.ly/javascript-graphing-library/range-slider/ seems to be an HTML/JS implementation of a custom slider bar that changes the x-axis range of a line chart. From what I've read, this approach seems to be Node.js only. Ideally, I'd like to implement something in just HTML/JS/JQuery/D3.js.
2) Alternatively, I could use a 2D contour plot instead of a 3D contourslice:
https://plot.ly/49/~txizzle/
However, now, I will need to have many of these contour plots. I'm not sure how I would switch between different contour plots with a slider.
My Questions:
1) How do I customize Plotly plots? Is this possible without relying on Node.js? I don't want to just embed the plots using Plotly's given auto-embedder, because it abstracts everything away.
2) Should I do a contourslice or many different contour plots?
3) How do I add a slider bar to switch the visibility of different contour slices, or how do I add a slider bar to switch different plots entirely?
Thank you for your time! Looking forward to explore Plotly more.
Since you used the MATLAB library to generate the plotly figure, you can add slider effects by embedding the plotly figure as an iframe in an offline HTML doc, then using Plotly's postmessage API.
Here's an example:
https://plot.ly/matlab/range-slider/
postMessage API:
https://github.com/plotly/postMessage-API

Matlab: Full 3D-Rotation with elevation higher +/-90

when rotating a 3D-plot in Matlab one can only rotate completely, so full 360°, around the z-axis (azimuthal angle) but only from +/-90° around the x/y-axes (elevation angle). I know that this includes all possible views in a spherical coordinate system, yet, a customer of mine would like to have the same functionality like in Fiji (3D-Viewer) or similar 3D-Viewers, to rotate fully about the 360° around an arbitary axis.
As simple demo:
surf(peaks); rotate3d on
I thought of a handles listener with callback when the view changes and then adjusting the azimuthal and elevation angles accordingly to generate the feeling of a full rotation but maybe someone has a better and simpler idea :)
Cheers Mika
I found a possible solution:
One can enable the camera control toolbar and use the camorbit functionality which does exactly what it should. In my GUI I just enable/disable it via a custom toggle button in the toolbar like so
if strcmp(get(handles.uitoggletool5,'State'),'on') == 1
cameratoolbar('SetMode','orbit');
else
cameratoolbar('SetMode','nomode');
end

Making a surf plot in a MATLAB GUI rotatable

I need to make a GUI in which you can rotate a surf plot. I currently have a surf plot in my GUI, but I can't rotate it whatsoever. Clicking it doesn't work, and it has no menu bar on top of it. Can someone help?
When you create a GUI with GUIDE, by default it will remove the toolbar and menubar from the GUI's figure window, by setting the 'Toolbar' and 'Menubar' properties of the figure to 'none'. That's usually a good thing, as there's a lot of functionality available in the figure toolbar and menubar that means it's difficult for you, as the GUI designer, to keep control of the workflow users will experience.
If you just want to make the surf plot rotatable, quickly, you can set the 'Toolbar' property of the figure to 'figure' using set(f, 'Toolbar', 'figure') if you have the handle f of the figure, or set(gcf, 'Toolbar', 'figure') if not - gcf is the handle to the current figure.
A better way would be to leave the toolbar off, and to maybe add a togglebutton uicontrol labelled "Rotate on/off". In the callback of this togglebutton, put some code that calls the command rotate3d on the axis of your surf plot to switch rotation on or off. Maybe do the same for panning, zooming as well. That way you can provide rotation while keeping control of the GUI workflow.