Multiple plots in a single figure not working correctly for pole plots

Hi,
I was reading a set of crystal euler angles in the format
phi1_1 phi_1 phi2_1
phi1_2 phi_2 phi2_2
...
...
...
phi1_n phi_n phi2_n
from an external file and use the following code to plot the pole figures
filename = 'pcrystal_standard.csv';
fileID = fopen(filename);
C = textscan(fileID,'%f %f %f');
fclose(fileID);
ncrys = cellfun(@length, C(1,1));
for i =1:ncrys
phi1=deg2rad(C{1,1}(i,1));
phi=deg2rad(C{1,2}(i,1));
phi2=deg2rad(C{1,3}(i,1));
ori = orientation.byEuler(phi1,phi,phi2,cs,ss);
h = Miller({1,0,0},cs);
r1 = ori * h.symmetrise;
plot(r1);
hold on;
end
hold off;
After plotting each of the crystal orientations, i hold the plot with "hold on;" to make sure the points are plotted in the same figure. One of the plot corresponding to the upper symmetry elements, fail to recognize the hold and does not add the points, while the lower one does it correctly. Attached figure might explain this better. Not sure why this happens, but probably some one has answers.

7 Commenti

No way to diagnose anything without the data file with which to try to recreate the problem...and any other prerequisites as well.
Just need this attached data file to run this code.
filename = 'pcrystal_standard.csv';
fileID = fopen(filename);
C = textscan(fileID,'%f %f %f');
fclose(fileID);
ncrys = cellfun(@length, C(1,1));
for i =1:ncrys
phi1=deg2rad(C{1,1}(i,1));
phi=deg2rad(C{1,2}(i,1));
phi2=deg2rad(C{1,3}(i,1));
ori = orientation.byEuler(phi1,phi,phi2,cs,ss);
h = Miller({1,0,0},cs);
r1 = ori * h.symmetrise;
plot(r1);
hold on;
end
Unable to resolve the name 'orientation.byEuler'.
hold off;
You might need to use Mtex, that can be downloaded here
Recommended to use 6.0 beta version
dpb
dpb il 18 Ott 2023
Modificato: dpb il 18 Ott 2023
That's expecting a lot from volunteers...why don't you attach the data to plot as .mat file instead?
Better yet, build a complete (simple/small) running example that illustrates the problem. You may find as a pleasant corollary to doing the above what caused the issue in the beginning and thereby solve you own problem...
cs and ss are undefined in the posted code.
Apologies. Please insert these these lines.
cs = crystalSymmetry('321');
ss = specimenSymmetry('1');

Accedi per commentare.

 Risposta accettata

Try this:
cs = crystalSymmetry('321');
ss = specimenSymmetry('1');
filename = 'pcrystal_standard.csv';
fileID = fopen(filename);
C = textscan(fileID,'%f %f %f');
fclose(fileID);
ncrys = cellfun(@length, C(1,1));
for i = 1:ncrys
phi1=deg2rad(C{1,1}(i,1));
phi=deg2rad(C{1,2}(i,1));
phi2=deg2rad(C{1,3}(i,1));
ori = orientation.byEuler(phi1,phi,phi2,cs,ss);
h = Miller({1,0,0},cs);
r1 = ori * h.symmetrise;
if i == 1
[~,ax] = plot(r1);
hold(ax,'on');
else
plot(r1,'parent',ax);
end
end
hold(ax,'off');
The idea is: the first time you plot, you store the two axes created (ax) by that plot call, then every subsequent time, you tell plot to plot into those same axes again. Also, you need to tell hold which axes to hold on and off.

8 Commenti

Here's another version that's a little cleaner, in my opinion. See comments in the code for changes.
cs = crystalSymmetry('321');
ss = specimenSymmetry('1');
filename = 'pcrystal_standard.csv';
% use readmatrix() to read that file. M is a matrix of the numbers:
M = readmatrix(filename);
% deg2rad() the whole thing at once, instead of inside the loop:
phi = deg2rad(M);
% ncrys is the number of rows in the matrix:
ncrys = size(phi,1);
% only need to compute h one time (doesn't depend on the loop variable i):
h = Miller({1,0,0},cs);
for i = 1:ncrys
ori = orientation.byEuler(phi(i,1),phi(i,2),phi(i,3),cs,ss);
r1 = ori * h.symmetrise;
if i == 1
[~,ax] = plot(r1);
hold(ax,'on');
else
plot(r1,'parent',ax);
end
end
hold(ax,'off');
Thanks Voss for the code. Pretty much what i wanted.
I was sifting through the help pages that can shows the 'parent' container of the axes given in the plot command, not being able to retrieve it. Could you send me the correct link for this please?
You're welcome! If this answer solves the problem, please click the Accept button to accept it.
I didn't really use the documentation; I only looked into the code. The plot function being called is \@vector3d\plot.m (I put breakpoints at the beginning of all the function files called plot in order to figure out which one was being called in this case), which calls \@vector3d\scatter.m, which calls \plotting\plotting_tools\newSphericalPlot.m.
The beginning of newSphericalPlot.m has comments describing different situations that seemed relevant:
function [sP, isNew] = newSphericalPlot(v,varargin)
% split plot in upper and lower hemisphere
%
% 1: axis given -> no sphericalRegion stored -> compute sphericalRegion -> finish
% 2: axis is hold and has sphericalRegion -> use multiplot
% 3: new multiplot
% get plotting convention
how2plot = getClass(varargin,'plottingConvention',getMTEXpref('xyzPlotting'));
% case 1: predefined axis
% -----------------------
if check_option(varargin,'parent')
ax = get_option(varargin,'parent');
% axis is already a spherical plot
if isappdata(ax(end),'sphericalPlot') && ishold(ax(end))
The code checks varargin (inputs 2-through-end to the newSphericalPlot function) for an argument called 'parent', so I figured that's how the function knows which axes to plot into in case you want to plot into existing axes. The code is also checking the hold state of the last axes given, ishold(ax(end)).
Also, these lines in \@vector3d\plot.m tell me what the output arguments from that function are, so I knew the axes were the second output:
if nargout >=1, varargout{1} = h; end
if nargout >=2, varargout{2} = ax; end
After verifying (still by looking at the relevant code files) that the arguments I send to \@vector3d\plot.m would ultimately be passed to \plotting\plotting_tools\newSphericalPlot.m, I tried the approach given in my answer: let the first plot call create the axes (and capture the axes as second output from plot) and then specify 'parent',ax in subsequent plot calls, and it worked.
(I also tried searching the documentation at some point, but it wasn't very helpful.)
Very well explained. Thanks Voss.
Not used to a plot() derivative creating multiple axes...that's unusual. Most return line or other graphics objects handles or a standalone chart object is a new aberration, but alternate returns and more than one axis -- that is, afaik, the only one???
It's from a third-party toolbox, which apparently doesn't follow the sensible plot() output convention that TMW has established.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Centro assistenza e File Exchange

Prodotti

Release

R2022b

Richiesto:

il 17 Ott 2023

Commentato:

il 20 Ott 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by