Skip to content

adding slice functionality to matlab_plotly and fix issue #312 #431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

gilbertogalvis
Copy link
Contributor

In favor of fixing all pending issues, this time I was working with issue #312. This issue is related to the MATLAB slice functionality. When trying to replicate the charts of the slice functionality, the previous matlab_plotly code resulted in bad plotly charts. This is basically because the slice functionality was not implemented in matlab_plotly. With this PR I have added this functionality by coding all the related code from scratch.

Specifically, I have fully coded the updateSlice.m file with which the charts of the slice functionality are now properly created with plotly.

It is important to note that to use the slice functionality, it is necessary to set the optional parameter 'TreatAs' to 'slice'.

Below I share examples of use taken from the MATLAB page

Volume Data Along Slices

Show volumetric data along slice planes that are orthogonal to each axis.
Create slice planes through the volume defined by v=xe−x2−y2−z2, where x, y, and z range from [-2,2]. Create slice planes orthogonal to the x-axis at the values -1.2, 0.8, and 2 and orthogonal to the z-axis at the value 0. Do not create any slice planes that are orthogonal to the y-axis by specifying an empty array.

[X,Y,Z] = meshgrid(-2:.2:2);
V = X.*exp(-X.^2-Y.^2-Z.^2);

xslice = [-1.2,0.8,2];   
yslice = [];
zslice = 0;
slice(X,Y,Z,V,xslice,yslice,zslice)

fig2plotly(gcf, 'offline', 1, 'treatAs', 'slice');

Screen Shot 2021-10-20 at 8 26 10 PM

Volume Data Along Surface

Show volumetric data along a nonplanar slice. Define the surface where you want to show the volumetric data.
Create volume array V as the volume defined by v=xe−x2−y2−z2, where x, y, and z range from [-5,5]. Then, show a slice of the volume data along the surface defined by z=x2−y2.

[X,Y,Z] = meshgrid(-5:0.2:5);
V = X.*exp(-X.^2-Y.^2-Z.^2);

[xsurf,ysurf] = meshgrid(-2:0.2:2);
zsurf = xsurf.^2-ysurf.^2;
slice(X,Y,Z,V,xsurf,ysurf,zsurf)

fig2plotly(gcf, 'offline', 1, 'treatAs', 'slice');

Screen Shot 2021-10-20 at 8 28 27 PM

Specify Interpolation Method

Create a slice plane through volumetric data. Specify the interpolation method for the data values.
Create a slice plane orthogonal to the x-axis at the value 0.8. Since the volume data is not defined for x values of 0.8, the slice function interpolates the nearby values. To use the nearest data point value, specify the interpolation method as 'nearest'.

[X,Y,Z] = meshgrid(-2:2);
V = X.*exp(-X.^2-Y.^2-Z.^2);
xslice = 0.8;   
yslice = [];
zslice = [];
slice(X,Y,Z,V,xslice,yslice,zslice,'nearest')

Screen Shot 2021-10-20 at 8 29 15 PM

EXTRA:

Previous example use FaceColor = 'flat' to coloring the slice surface chart. But the updated code works for FaceColor = 'interp' as well.

[X,Y,Z] = meshgrid(-2:2);
V = X.*exp(-X.^2-Y.^2-Z.^2);
xslice = 0.8;   
yslice = [];
zslice = [];
s = slice(X,Y,Z,V,xslice,yslice,zslice,'nearest');

s(1).FaceColor = 'interp';

fig2plotly(gcf, 'offline', 1, 'treatAs', 'slice');

Bellow the result. Please note how the face color is now corresponding to interp

Screen Shot 2021-10-20 at 8 29 34 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants