File Exchange

image thumbnail

pcolor3

version 1.1.0.0 (658 KB) by Chad Greene
Plot a 3D matrix as a semitransparent volume

24 Downloads

Updated 12 Mar 2015

View License

Note: This function does not yet work for Matlab 2014b or later.
This function plots a 3D data volume as color-scaled semitransparent surface planes in each dimension.

Syntax
pcolor3(V)
pcolor3(X,Y,Z,V)
pcolor3(...,'alpha',AlphaValue)
pcolor3(...,'edgealpha',EdgeAlphaValue)
pcolor3(...,'alphalim',AlphaLimits)
pcolor3(...,InterpolationMethod)
pcolor3(...,'N',NumberOfSlices)
pcolor3(...,'Nx',NumberOfXSlices)
pcolor3(...,'Ny',NumberOfYSlices)
pcolor3(...,'Nz',NumberOfZSlices)
h = pcolor3(...)

Description
pcolor3(V) plots a field of 3D volume V.

pcolor3(X,Y,Z,V) plots 3D volume V at locations given by X,Y,Z. X, Y, and Z can be 3D matrices matching the dimensions of V, or 1D arrays.

pcolor3(...,'alpha',AlphaValue) specifies a volume transparency value between 0 (completely transparent) and 1 (completely opaque). Default AlphaValue is 0.01. This value may seem surprisingly low, but remember that you'll be looking through 100 slices--they add up.

pcolor3(...,'edgealpha',EdgeAlphaValue) specifies transparency of sides of the volume faces of the volume. An EdgeAlphaValue greater than the volume AlphaValue helps define corners and edges, especially in the presence of lighting objects. Default EdgeAlphaValue is 0.05.

pcolor3(...,'alphalim',AlphaLimits) scales transparency values with values of V. This can help highlight a variable of interest by making low V values invisible. AlphaLimits is a two-element array corresponding of values in V. If AlphaLimits is 'auto', AlphaLimits is taken as [min(V(:)) max(V(:))].

Tip: If interesting values diverge about an uninteresting mean (e.g., temperature of 25 is not interesting whereas T = 10 is interesting and T = 40 is also interesting), use 'alphalim',[25 40] and select a colormap that diverges from 25. Although T = 10 is well below the minimum AlphaLimits, 10 and 40 are equidistant from 25 and are therefore given equal opacity.

pcolor3(...,InterpolationMethod) specifies an interpolation method as:

'linear' trilinear slice interpolation (default),
'cubic' tricubic slice interpolation,
'nearest' nearest-neighbor slice interpolation, or
'direct' plots data directly instead of interpolated slices (fastest?).

pcolor3(...,'N',NumberOfSlices) specifies a number of slices in each direction. Default value is 100. Increasing number of slices can make a smoother, higher quality graphic, but may slow performance.

pcolor3(...,'Nx',NumberOfXSlices) specifies a number of slices in the x direction. Default value is 100.

pcolor3(...,'Ny',NumberOfYSlices) specifies a number of slices in the y direction. Default value is 100.

pcolor3(...,'Nz',NumberOfZSlices) specifies a number of slices in the z direction. Default value is 100.

h = pcolor3(...) returns a vector of handles to surface graphics objects.

Comments and Ratings (13)

It's OK

In version 2014, It not work.

Binxu

It seems using this pcolor function to visualize a 400, 200, 40 volume will entirely crash the matlab together.....

Jie Yang

Here is how to make it work in later versions:

set(gcf, 'Renderer', 'painters');

Meg Noah

Nice script! It works in 2018 if you do a global search and replace:
,'facealpha','flat' -> ,'facecolor','interp','facealpha','interp'

Xin

Xin

My matlab is 2017 but it says the code does not work on matlab 2014b

Not working anymore on recent versions

Matt L.

Looks so perfect ... but :
Warning: The pcolor3 function does not work quite right on Matlab R2014b.
Please, make an update, it will be well appreciated !

Hi, thanks for this code.

I have troubles to run this code. The error related to rgb function, it says that "Cannot find an rgb value for the color blue". Also, I have got this message which saying that "Cannot find the xkcd_rgb_data.mat. I will try to install it from rgb.txt now. I do not find the xkcd_rgb_data.mat, where should I find it.

Hi,

Thanks for Uploading this.

I am trying to change the colormap linear scale to logarithimic using pcolor3 function . I've been attempting to do this by first log-transforming and scaling the data ,calling pcolor3 function and then making a log-scale colorbar using the set function.

This method seems to work with the only problem that I loose the semi-transparency feature I set with pcolor3 initially. That is, I only see the sides of the cube.

Is there a different way to do this?

Chad Greene

Yi: I've run into that problem with R2014b. If you're using an older version of Matlab pcolor3 should work. Try switching the renderer to opengl via

set(gcf,'renderer','opengl')

Hope that helps.

Yi Du

Great job.
But I tried your function with the demo mri data, only to find out invisible rendering except the first slice.
Did you find that?

Updates

1.1.0.0

Added features for alpha scaling and direct (no interpolation) plotting.

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux

pcolor3/html/