forked from mtex-toolbox/mtex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotAngleDistribution.m
117 lines (94 loc) · 2.71 KB
/
plotAngleDistribution.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
function h = plotAngleDistribution(obj,varargin)
% plot axis distribution
%
% Syntax
%
% plotAngleDistribution(mdf)
% plotAngleDistribution(CS1,CS2)
% plotAngleDistribution(grains.boundary.misorientation)
%
% Input
% CS - @symmetry
%
% Options
% resolution - resolution of the plots
%
[mtexFig,isNew] = newMtexFigure(varargin{:});
mtexFig.keepAspectRatio = false;
% compute angles
plotType = 'line';
if isa(obj,'symmetry')
maxOmega = maxAngle(obj,varargin{:});
else
maxOmega = maxAngle(obj.CS,obj.SS);
if ~isa(obj,'ODF'), plotType = 'bar'; end
end
% seach for existing bar plots and adjust bar center
h = findobj(mtexFig.gca,'type','bar','-or','type','hgGroup');
h = flipud(h(:));
unit = '%';
if ~isempty(h)
midPoints = ensurecell(get(h,'XData'));
midPoints= midPoints{1}*degree;
bins = [2*midPoints(1)-midPoints(2),midPoints,2*midPoints(end)-midPoints(end-1)];
bins = (bins(1:end-1) + bins(2:end))/2;
density = ensurecell(get(h,'YData'));
density = cellfun(@(x) x(:),density,'UniformOutput',false);
density = horzcat(density{:});
lg = ensurecell(get(h,'DisplayName'));
if strcmp(plotType,'bar')
delete(h); % remove old bars
% add a new column
density(:,end+1) = 0;
% maybe we have to enlarge bins
if maxOmega > max(bins)
bins = 0:(bins(2)-bins(1)):maxOmega + 0.01;
density(end+1:length(bins)-1,:) = 0;
end
else
faktor = 100 / size(density,1);
end
else
if strcmp(plotType,'bar')
% bin size given?
if max(obj.angle) < maxOmega/2, maxOmega = max(obj.angle);end
nbins = round(maxOmega/get_option(varargin,'resolution',5*degree));
% compute bins
bins = linspace(-eps,maxOmega+0.01,nbins);
density = zeros(nbins-1,1);
lg = {};
elseif check_option(varargin,'percent')
faktor = 100;
else
faktor = 1;
unit = 'mrd';
end
end
% compute angle distribution
if isa(obj,'symmetry') || isa(obj,'ODF')
[density,omega] = calcAngleDistribution(obj,varargin{:});
else
d = histc(obj.angle,bins).';
midPoints = 0.5*(bins(1:end-1) + bins(2:end));
density(:,end) = 100 * d(1:end-1) ./ sum(d);
end
% plot angle distribution
if strcmp(plotType,'bar')
h = optiondraw(bar(midPoints/degree,density,'parent',mtexFig.gca),varargin{:});
xlim(mtexFig.gca,[0,max(bins)/degree])
% update legend
lg = [lg;{[obj.CS.mineral '-' obj.SS.mineral]}];
for i=1:length(h)
set(h(i),'DisplayName',lg{i});
end
else
h = optiondraw(plot(omega/degree,faktor * max(0,density),...
'parent',mtexFig.gca),'LineWidth',2,varargin{:});
end
% finish
if isNew
xlabel(mtexFig.gca,'Misorientation angle (degrees)');
ylabel(mtexFig.gca,['Frequency (' unit ')']);
drawNow(mtexFig,varargin{:});
end
if nargout == 0, clear h; end