mtex-toolbox / mtex

MTEX is a free Matlab toolbox for quantitative texture analysis. Homepage:
http://mtex-toolbox.github.io/
GNU General Public License v2.0
291 stars 186 forks source link

IPF scatter plot errors when passing MarkerSize #2130

Closed creuzige closed 7 months ago

creuzige commented 7 months ago

What do you want to do? I'd like to plot some EBSD data onto an IPF Scatter Plot using the square root of the grainsize for the marker size. In this data set, I have only a few orientations that I'm trying to project (and trying to visually make the point that one shouldn't trust the contour plots due to the sparse data).

What result do you get

If there 'enough' data points, I get the expected plot (similar to https://mtex-toolbox.github.io/EBSDIPFMap.html). If there are too few orientations, I get the error message below. The boundary between enough and too few seems partially dependent on the distribution, but when I have 171 orientations it worked (m3m symmetry), but 49 it failed.

Error Message

Error using scatter
X, Y, and size arguments must be vectors of the same length, matrices of the same size, or a mix of vectors and matrices where the length of the vectors matches either the number of rows or columns of the
matrices.

Error in vector3d/scatter (line 164)
      h(i) = optiondraw(scatter(x(:),y(:),MarkerSize(:),'parent',sP(i).hgt,...

Error in Miller/scatter (line 60)
[varargout{1:nargout}] = scatter@vector3d(m,varargin{:},m.CS);

Error in vector3d/plot (line 99)
    [varargout{1:nargout}] = v.scatter(varargin{:});

Error in indexing (line 20)
    [varargout{1:nargout}] = builtin('subsref',v,s);

Error in orientation/plotIPDF (line 82)
  [~,cax] = h.plot(repmat(data,1,length(rSym)),'symmetrised',...

I added some display commands to vector3d/scatter,

    % draw patches
    if numel(MarkerSize) > 1

->      disp('Array Sizes')
->      size(x(:))
->      size(y(:))
->      size(MarkerSize(:))

      h(i) = optiondraw(scatter(x(:),y(:),MarkerSize(:),'parent',sP(i).hgt,...
        'MarkerFaceColor',mfc,'MarkerEdgeColor',mec),varargin{:}); %#ok<AGROW>      

and found

Array Sizes

ans =

        2352           1

ans =

        2352           1

ans =

    49     1

The fact that it's off by a factor of 48 on m3m symmetry made me suspicious. I think the issue is that if there a lot of gaps in the data, the x and y values sometimes get filled with nans, but the MarkerSize does not get filled in.

    % and fill the gaps with nans
    for k = 1:numel(ind)
      x = [x(1:ind(k)+k-1);nan;x(ind(k)+k:end)];
      y = [y(1:ind(k)+k-1);nan;y(ind(k)+k:end)];
    end

What MTEX version do you use? 5.11.2

creuzige commented 7 months ago

@ralfHielscher I patched my code with the changes in 2c37af6, but still got the same errors. I'll send the job_variable.mat file I've been working with.

>> load('job_variable.mat')
>> plotIPDF(job.parentGrains.meanOrientation,xvector,'points','all','marker','o',...
    'MarkerSize',sqrt(job.parentGrains.grainSize), 'MarkerEdgeColor','k','MarkerFaceColor','k');
Array Sizes

ans =

        2352           1

ans =

        2352           1

ans =

    49     1

Error using scatter
X, Y, and size arguments must be vectors of the same length, matrices of the same size, or a mix of vectors and matrices where the length of
the vectors matches either the number of rows or columns of the matrices.

Error in vector3d/scatter (line 163)
      h(i) = optiondraw(scatter(x(:),y(:),MarkerSize(:),'parent',sP(i).hgt,...

Error in Miller/scatter (line 60)
[varargout{1:nargout}] = scatter@vector3d(m,varargin{:},m.CS);

Error in vector3d/plot (line 99)
    [varargout{1:nargout}] = v.scatter(varargin{:});

Error in indexing (line 20)
    [varargout{1:nargout}] = builtin('subsref',v,s);

Error in orientation/plotIPDF (line 89)
  [~,cax] = h.plot(repmat(data,1,length(rSym)),'symmetrised',...