Skip to content

Commit

Permalink
Finish multiplot which allows to plot upper and lower hemispheres in …
Browse files Browse the repository at this point in the history
…pole figure and ODF plots and

fixes #291
  • Loading branch information
ralfHielscher committed Feb 14, 2018
2 parents 5381932 + d8c73dd commit 317b82b
Show file tree
Hide file tree
Showing 35 changed files with 358 additions and 243 deletions.
16 changes: 9 additions & 7 deletions ODFAnalysis/@ODF/plotIPDF.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,27 @@ function plotIPDF(odf,r,varargin)
[mtexFig,isNew] = newMtexFigure('datacursormode',@tooltip,varargin{:});

for i = 1:length(r)
if i>1, mtexFig.nextAxis; end

mtexFig.nextAxis;

% compute inverse pole figures
p = ensureNonNeg(odf.calcPDF(h,r(i),varargin{:}));

% plot
h.plot(p,'parent',mtexFig.gca,'doNotDraw','smooth',varargin{:});
mtexTitle(mtexFig.gca,char(r(i),'LaTeX'));
[~,cax] = h.plot(p,'doNotDraw','smooth',varargin{:});

% store geometry
set(cax,'tag','ipdf');
setappdata(cax,'inversePoleFigureDirection',r(i));
setappdata(cax,'CS',odf.CS);
setappdata(cax,'SS',odf.SS);

end


if isNew % finalize plot

mtexFig.drawNow('figSize',getMTEXpref('figSize'),varargin{:});
setappdata(gcf,'inversePoleFigureDirection',r);
setappdata(gcf,'CS',odf.CS);
setappdata(gcf,'SS',odf.SS);
set(gcf,'tag','ipdf');
set(gcf,'Name',['Inverse Pole Figures of ',inputname(1)]);

end
Expand Down
46 changes: 34 additions & 12 deletions ODFAnalysis/@ODF/plotPDF.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,54 @@ function plotPDF(odf,h,varargin)
argin_check([h{:}],'Miller');
for i = 1:length(h), h{i} = odf.CS.ensureCS(h{i}); end



% plotting grid
sR = fundamentalSector(odf.SS,varargin{:});
r = plotS2Grid(sR,varargin{:});
rAll = plotS2Grid(sR,varargin{:});
if any(rAll.z(:) < 1e-2) && any(rAll.z(:) > 1e-2) && ~check_option(varargin,'complete')
rUpper = plotS2Grid(sR,'upper',varargin{:});
else
rUpper = rAll;
end
if isa(odf.SS,'crystalSymmetry')
rAll = Miller(rAll,odf.CS);
rUpper = Miller(rUpper,odf.CS);
pfAnnotations = @(varargin) [];
else
pfAnnotations = getMTEXpref('pfAnnotations');
end

% create a new figure if needed
[mtexFig,isNew] = newMtexFigure('datacursormode',@tooltip,varargin{:});
pfAnnotations = getMTEXpref('pfAnnotations');


for i = 1:length(h)

if i>1, mtexFig.nextAxis; end

% create a new axis
if ~isstruct(mtexFig), mtexFig.nextAxis; end

% maybe we need only one hemisphere
if all(angle(h{i},-h{i})<1e-2)
rLocal = rUpper;
else
rLocal = rAll;
end
% compute pole figures
p = ensureNonNeg(odf.calcPDF(h{i},r,varargin{:},'superposition',c{i}));
p = ensureNonNeg(odf.calcPDF(h{i},rLocal,varargin{:},'superposition',c{i}));

r.plot(p,'parent',mtexFig.gca,'smooth','doNotDraw',varargin{:});
pfAnnotations('parent',mtexFig.gca,'doNotDraw');

% plot the pole figure
mtexTitle(mtexFig.gca,char(h{i},'LaTeX'));
[~,cax] = rLocal.plot(p,'smooth','doNotDraw',varargin{:});

% plot annotations
pfAnnotations('parent',cax,'doNotDraw','add2all');
set(cax,'tag','pdf');
setappdata(cax,'h',h{i});
setappdata(cax,'SS',odf.SS);

end

if isNew % finalize plot
set(gcf,'tag','pdf');
setappdata(gcf,'SS',odf.SS);
setappdata(gcf,'h',h);
set(gcf,'Name',['Pole figures of "',inputname(1),'"']);

dcm = mtexFig.dataCursorMenu;
Expand Down
8 changes: 6 additions & 2 deletions S2Fun/@S2Fun/plot.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@
% create a new figure if needed
[mtexFig,isNew] = newMtexFigure('datacursormode',@tooltip,varargin{:});

%
if sF.antipodal, varargin = [varargin,'antipodal']; end

% generate a grid where the function will be plotted
plotNodes = plotS2Grid(varargin{:});

% evaluate the function on the plotting grid
values = sF.eval(plotNodes);

h = [];
for j = 1:length(sF)

if j > 1, mtexFig.nextAxis; end

% plot the function values
h(j) = plot(plotNodes,values(:,j),'parent',mtexFig.gca,'contourf',varargin{:}); %#ok<AGROW>
h = [h,plot(plotNodes,values(:,j),'contourf','hold',varargin{:})]; %#ok<AGROW>

end

Expand Down
4 changes: 2 additions & 2 deletions S2Fun/doc/S2FunHarmonic_uni_index.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
% *Definition via function values*
%
% At first you need some vertices
nodes = equispacedS2Grid('resolution',3*degree);
nodes = equispacedS2Grid('resolution',3*degree,'antipodal');
nodes = nodes(:);
%%
% Next you define function values for the vertices
y = smiley(nodes);

% plot the discrete data
plot(nodes,y,'upper')
plot(nodes,y)

%%
% Now the actual command to get |sF1| of type |S2FunHarmonic|
Expand Down
3 changes: 3 additions & 0 deletions S2Fun/tools/smiley.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
c_0 = [0.5; -0.5; -0.5; 0.25; 0.25; 0.25; 0.25; 0.25];

centers = vector3d('polar', x_0(:, 1), x_0(:, 2));
if strcmpi(getMTEXpref('xAxisDirection'),'east')
centers = rotate(centers,90*degree);
end

fh = @(v) (sum(c_0.*f_r(dot(v, centers), h_0), 1))';

Expand Down
2 changes: 1 addition & 1 deletion doc/CrystalGeometry/CrystalSymmetries.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
h = Miller({1,0,-1,0},{1,1,-2,0},{1,0,-1,1},{1,1,-2,1},{0,0,0,1},cs);

for i = 1:length(h)
plot(h(i),'symmetrised','labeled','backgroundColor','w','doNotDraw','grid')
plot(h(i),'symmetrised','labeled','backgroundColor','w','doNotDraw','grid','upper')
hold all
end
hold off
Expand Down
4 changes: 2 additions & 2 deletions doc/CrystalGeometry/MorawiecCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@

plotSection(rotZ,'MarkerColor','b','axisAngle',(30:30:180)*degree)
hold on
plotSection(rotX,'MarkerColor','g')
plot(rotX,'MarkerColor','g','add2all')
hold on
plotSection(rotY,'MarkerColor','r')
plot(rotY,'MarkerColor','r','add2all')
hold off

%% Crystal Symmetries
Expand Down
36 changes: 11 additions & 25 deletions doc/ODFAnalysis/ModelODFs.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
% adding and subtracting arbitrary ODFs. Model ODFs may be used as
% references for ODFs estimated from pole figure data or EBSD data and are
% instrumental for <PoleFigureSimulation_demo.html pole figure simulations>
% and <EBSDSimulation_demo.html single orientation simulations>. These
% relationships are visualized in the following chart.
%
% <<odf.png>>
% and <EBSDSimulation_demo.html single orientation simulations>.

%% The Uniform ODF
%
Expand Down Expand Up @@ -67,29 +64,18 @@


%% Fibre ODFs
% A fibre is a rotation mapping a <Miller_index.html crystal direction> $h
% \in S^2$ onto a <vector3d_index.html specimen direction> $r \in S^2$,
% i.e.
%
% $$g*h = r.$$
%
% A fibre ODF may be written as
%
% $$f(g; h,r) = \psi(\angle(g*h,r)),\quad g \in SO(3),$$
%
% with an arbitrary <kernel_index.html radially symmetrial
% function> $\psi$. In order to define a fibre ODF one needs
%
% * a <Miller_index.html crystal direction> *h0*
% * a <vector3d_index.html specimen direction> *r0*
% * a <kernel_index.html kernel> function *psi* defining the shape
% * the crystal and specimen <symmetry_index.html symmetry>
% A fibre is represented in MTEX by a variable of type <fibre_index.html
% fibre>.

h = Miller(0,0,1,cs);
r = xvector;
odf = fibreODF(h,r,ss,psi)
% define the fibre to be the beta fibre
f = fibre.beta(cs)

% define a fibre ODF
odf = fibreODF(f,ss,psi)

% plot the odf in 3d
plot3d(odf)

plotPDF(odf,[Miller(1,0,0,cs),Miller(1,1,0,cs)],'antipodal')

%% ODFs given by Fourier coefficients
%
Expand Down
43 changes: 22 additions & 21 deletions doc/ODFAnalysis/ODFPlot.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,17 @@
% arguments are the ODF to be plotted and the <Miller_index.html Miller
% indice> of the crystal directions you want to have pole figures for.

plotPDF(odf,[Miller(1,0,-1,0,cs),Miller(0,0,0,1,cs)])
plotPDF(odf,Miller({1,0,-1,0},{0,0,0,1},{1,1,-2,1},cs))

%%
% By default the <ODF.plotPDF.html plotPDF> command plots only the upper
% hemisphere of each pole sphere. In order to plot upper and lower
% hemisphere you can do the following
% While the first two pole figures are plotted on the upper hemisphere
% only the (11-21) has been plotted for the upper and lower hemisphere. The
% reason for this behaviour is that MTEX automatically detects that the
% first two pole figures coincide on the upper and lower hemisphere while
% the (11-21) pole figure does not. In order to plot all pole figures with
% upper and lower hemisphere we can do

mtexFig = mtexFigure;

plotPDF(odf,Miller(1,1,-2,1,cs),'TR','upper','parent',mtexFig.nextAxis)

plotPDF(odf,Miller(1,1,-2,1,cs),'TR','lower','parent',mtexFig.nextAxis)

mtexFig.drawNow
plotPDF(odf,Miller({1,0,-1,0},{0,0,0,1},{1,1,-2,1},cs),'complete')

%%
% We see that in general upper and lower hemisphere of the pole figure do
Expand All @@ -58,30 +55,33 @@
%
% In MTEX antipodal symmetry can be enforced by the use the option *antipodal*.

mtexFig = mtexFigure;

plotPDF(odf,Miller(1,1,-2,1,cs),'TR','upper','antipodal','parent',mtexFig.nextAxis)

plotPDF(odf,Miller(1,1,-2,1,cs),'TR','lower','antipodal','parent',mtexFig.nextAxis)

mtexFig.drawNow

plotPDF(odf,Miller(1,1,-2,1,cs),'antipodal','complete')

%% Inverse Pole Figures
% Plotting inverse pole figures is analogously to plotting pole figures
% with the only difference that you have to use the command
% <ODF.plotIPDF.html plotIPDF> and you to specify specimen directions and
% not crystal directions.

plotIPDF(odf,[xvector,zvector])

%%
% Imposing antipodal symmetry to the inverse pole figures halfes the
% fundamental region

plotIPDF(odf,[xvector,zvector],'antipodal')
annotate(Miller(1,0,-1,0,odf.CS,'UVTW'),'labeled')

%%
% By default MTEX always plots only the fundamental region with respect to
% the crystal symmetry. In order to plot the complete inverse pole figure
% you have to use the option *complete*.

plotIPDF(odf,[xvector,zvector],'antipodal','complete')
plotIPDF(odf,[xvector,zvector],'complete','upper')

%%
% This illustrates also more clearly the effect of the antipodal symmetry

plotIPDF(odf,[xvector,zvector],'complete','antipodal','upper')

%% ODF Sections
%
Expand Down Expand Up @@ -160,6 +160,7 @@
% and the distribution of the missorientation angles and compare them to a
% uniform ODF

close all
plotAngleDistribution(mdf)
hold all
plotAngleDistribution(cs,cs)
Expand Down
25 changes: 12 additions & 13 deletions doc/Plotting/CombinedPlots_demo.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,28 @@

plotPDF(odf,h,'antipodal','contourf','grid')
mtexColorMap white2black
hold all
plotPDF(ori,h,'antipodal','DisplayName','EBSD 1',...
'MarkerSize',5,'MarkerColor','b','MarkerEdgeColor','w')
hold all
plotPDF(ori_rotated,h,'DisplayName','EBSD 2',...
'MarkerSize',5,'MarkerColor','r','MarkerEdgeColor','k');
hold off

legend('show','location','southeast')
plot(ori,'DisplayName','EBSD 1',...
'MarkerSize',5,'MarkerColor','b','MarkerEdgeColor','w','add2all')

plot(ori_rotated,'DisplayName','EBSD 2',...
'MarkerSize',5,'MarkerColor','r','MarkerEdgeColor','k','add2all');

legend('show','location','northeast')

%%
% and, of course, you can do the same with ODF plots:

plot(odf,'sections',8,'contourf','sigma')
mtexColorMap white2black
hold all
plot(ori,'MarkerSize',6,'MarkerColor','b','MarkerEdgeColor','w')
plot(ori_rotated,'MarkerSize',6,'MarkerColor','r','MarkerEdgeColor','k');
hold off
plot(ori,'MarkerSize',6,'MarkerColor','b','MarkerEdgeColor','w','add2all')
plot(ori_rotated,'MarkerSize',6,'MarkerColor','r','MarkerEdgeColor','k','add2all');

%% Add Miller Indices to an Inverse Pole Figure Plot
% Next, we are going to add some Miller indices to an inverse pole figure
% plot.

plotIPDF(odf,xvector);
plotIPDF(odf,xvector,'noLabel');
mtexColorMap white2black

hold all % keep plot
Expand All @@ -90,6 +87,8 @@
plot(Miller(0,1,-1,1,cs),'symmetrised','labeled','backgroundColor','w')
hold off % next plot command deletes all plots



%% Combining different plots in one figure
% The next example demonstrates how to arrange arbitrary plots into one
% figure
Expand Down
Loading

0 comments on commit 317b82b

Please sign in to comment.