@@ -105,8 +105,8 @@ def plotGrainNumbers(self, dilateBoundaries=False, ax=None, **kwargs):
105
105
Set to true to dilate boundaries.
106
106
ax : matplotlib.axes.Axes, optional
107
107
axis to plot on, if not provided the current active axis is used.
108
- kwargs : dict
109
- Keyword arguments to pass to matplotlib.
108
+ kwargs : dict, optional
109
+ Keyword arguments passed to :func:`defdap.plotting.MapPlot.addGrainNumbers`
110
110
111
111
Returns
112
112
-------
@@ -129,6 +129,8 @@ def locateGrainID(self, clickEvent=None, displaySelected=False, **kwargs):
129
129
Click handler to use.
130
130
displaySelected : bool, optional
131
131
If true, plot slip traces for grain selected by click.
132
+ kwargs : dict, optional
133
+ Keyword arguments passed to :func:`defdap.base.Map.plotDefault`
132
134
133
135
"""
134
136
# Check that grains have been detected in the map
@@ -157,33 +159,41 @@ def clickGrainID(self, event, plot, displaySelected):
157
159
----------
158
160
event :
159
161
Click event.
160
- plot : defdap.plotting.Plot
162
+ plot : defdap.plotting.MapPlot
161
163
Plot to capture clicks from.
162
164
displaySelected : bool
163
165
If true, plot the selected grain alone in pop-out window.
164
166
165
167
"""
166
- if event .inaxes is plot .ax :
167
- # grain id of selected grain
168
- self .currGrainId = int (self .grains [int (event .ydata ), int (event .xdata )] - 1 )
169
- print ("Grain ID: {}" .format (self .currGrainId ))
170
-
171
- # update the grain highlights layer in the plot
172
- plot .addGrainHighlights ([self .currGrainId ], alpha = self .highlightAlpha )
173
-
174
- if displaySelected :
175
- currGrain = self [self .currGrainId ]
176
- if self .grainPlot is None or not self .grainPlot .exists :
177
- self .grainPlot = currGrain .plotDefault (makeInteractive = True )
178
- else :
179
- self .grainPlot .clear ()
180
- self .grainPlot .callingGrain = currGrain
181
- currGrain .plotDefault (plot = self .grainPlot )
182
- self .grainPlot .draw ()
168
+ # check if click was on the map
169
+ if event .inaxes is not plot .ax :
170
+ return
171
+
172
+ # grain id of selected grain
173
+ self .currGrainId = int (self .grains [int (event .ydata ), int (event .xdata )] - 1 )
174
+ print ("Grain ID: {}" .format (self .currGrainId ))
175
+
176
+ # update the grain highlights layer in the plot
177
+ plot .addGrainHighlights ([self .currGrainId ], alpha = self .highlightAlpha )
178
+
179
+ if displaySelected :
180
+ currGrain = self [self .currGrainId ]
181
+ if self .grainPlot is None or not self .grainPlot .exists :
182
+ self .grainPlot = currGrain .plotDefault (makeInteractive = True )
183
+ else :
184
+ self .grainPlot .clear ()
185
+ self .grainPlot .callingGrain = currGrain
186
+ currGrain .plotDefault (plot = self .grainPlot )
187
+ self .grainPlot .draw ()
183
188
184
189
def drawLineProfile (self , ** kwargs ):
185
190
"""Interactive plot for drawing a line profile of data.
186
191
192
+ Parameters
193
+ ----------
194
+ kwargs : dict, optional
195
+ Keyword arguments passed to :func:`defdap.base.Map.plotDefault`
196
+
187
197
"""
188
198
plot = self .plotDefault (makeInteractive = True , ** kwargs )
189
199
@@ -198,21 +208,25 @@ def calcLineProfile(self, plot, startEnd, **kwargs):
198
208
199
209
Parameters
200
210
----------
201
- plot : defdap.plotting.Plot
211
+ plot : defdap.plotting.MapPlot
202
212
Plot to calculate the line profile for.
203
213
startEnd : array_like
204
214
Selected points (x0, y0, x1, y1).
215
+ kwargs : dict, optional
216
+ Keyword arguments passed to :func:`matplotlib.pyplot.plot`
205
217
206
218
"""
207
-
208
219
x0 , y0 = startEnd [0 :2 ]
209
220
x1 , y1 = startEnd [2 :4 ]
210
221
profile_length = np .sqrt ((y1 - y0 ) ** 2 + (x1 - x0 ) ** 2 )
211
222
212
223
# Extract the values along the line
213
- zi = profile_line (plot .imgLayers [0 ].get_array (),
214
- (startEnd [1 ], startEnd [0 ]), (startEnd [3 ], startEnd [2 ]),
215
- mode = 'nearest' , ** kwargs )
224
+ zi = profile_line (
225
+ plot .imgLayers [0 ].get_array (),
226
+ (startEnd [1 ], startEnd [0 ]),
227
+ (startEnd [3 ], startEnd [2 ]),
228
+ mode = 'nearest'
229
+ )
216
230
xi = np .linspace (0 , profile_length , len (zi ))
217
231
218
232
if self .profilePlot is None or not self .profilePlot .exists :
@@ -237,7 +251,7 @@ def setHomogPoint(self, binSize=1, points=None, **kwargs):
237
251
points : numpy.ndarray, optional
238
252
Array of (x,y) homologous points to set explicitly.
239
253
kwargs : dict, optional
240
- Keyword arguments for matplotlib.
254
+ Keyword arguments passed to :func:`defdap.base.Map.plotHomog`
241
255
242
256
"""
243
257
if points is None :
@@ -269,17 +283,20 @@ def clickHomog(self, event, plot):
269
283
----------
270
284
event :
271
285
Click event.
272
- plot : defdap.plotting.Plot
286
+ plot : defdap.plotting.MapPlot
273
287
Plot to monitor.
274
288
275
289
"""
276
- if event .inaxes is plot .ax :
277
- # right mouse click or shift + left mouse click
278
- # shift click doesn't work in osx backend
279
- if (event .button == 3 or
280
- (event .button == 1 and event .key == 'shift' )):
281
- plot .addPoints ([int (event .xdata )], [int (event .ydata )],
282
- updateLayer = 1 )
290
+ # check if click was on the map
291
+ if event .inaxes is not plot .ax :
292
+ return
293
+
294
+ # right mouse click or shift + left mouse click
295
+ # shift click doesn't work in osx backend
296
+ if (event .button == 3 or
297
+ (event .button == 1 and event .key == 'shift' )):
298
+ plot .addPoints ([int (event .xdata )], [int (event .ydata )],
299
+ updateLayer = 1 )
283
300
284
301
def keyHomog (self , event , plot ):
285
302
"""Event handler for moving position using keyboard after clicking on a map.
@@ -288,7 +305,7 @@ def keyHomog(self, event, plot):
288
305
----------
289
306
event :
290
307
Keypress event.
291
- plot : defdap.plotting.Plot
308
+ plot : defdap.plotting.MapPlot
292
309
Plot to monitor.
293
310
294
311
"""
@@ -324,7 +341,7 @@ def clickSaveHomog(self, event, plot, binSize):
324
341
----------
325
342
event :
326
343
Button click event.
327
- plot : defdap.plotting.Plot
344
+ plot : defdap.plotting.MapPlot
328
345
Plot to monitor.
329
346
binSize : int, optional
330
347
Binning applied to image, if applicable.
@@ -457,41 +474,43 @@ def clickGrainNeighbours(self, event, plot):
457
474
----------
458
475
event :
459
476
Click event.
460
- plot : defdap.plotting.Plot
477
+ plot : defdap.plotting.MapPlot
461
478
Plot to monitor.
462
479
463
480
"""
464
- if event .inaxes is plot .ax :
465
- # grain id of selected grain
466
- grainId = int (self .grains [int (event .ydata ), int (event .xdata )] - 1 )
467
- if grainId < 0 :
468
- return
469
- self .currGrainId = grainId
470
- grain = self [grainId ]
481
+ # check if click was on the map
482
+ if event .inaxes is not plot .ax :
483
+ return
471
484
472
- # find first and second nearest neighbours
473
- firstNeighbours = list (self .neighbourNetwork .neighbors (grain ))
474
- highlightGrains = [grain ] + firstNeighbours
475
-
476
- secondNeighbours = []
477
- for firstNeighbour in firstNeighbours :
478
- trialSecondNeighbours = list (
479
- self .neighbourNetwork .neighbors (firstNeighbour )
480
- )
481
- for secondNeighbour in trialSecondNeighbours :
482
- if (secondNeighbour not in highlightGrains and
483
- secondNeighbour not in secondNeighbours ):
484
- secondNeighbours .append (secondNeighbour )
485
- highlightGrains .extend (secondNeighbours )
486
-
487
- highlightGrains = [grain .grainID for grain in highlightGrains ]
488
- highlightColours = ['white' ]
489
- highlightColours .extend (['yellow' ] * len (firstNeighbours ))
490
- highlightColours .append ('green' )
491
-
492
- # update the grain highlights layer in the plot
493
- plot .addGrainHighlights (highlightGrains ,
494
- grainColours = highlightColours )
485
+ # grain id of selected grain
486
+ grainId = int (self .grains [int (event .ydata ), int (event .xdata )] - 1 )
487
+ if grainId < 0 :
488
+ return
489
+ self .currGrainId = grainId
490
+ grain = self [grainId ]
491
+
492
+ # find first and second nearest neighbours
493
+ firstNeighbours = list (self .neighbourNetwork .neighbors (grain ))
494
+ highlightGrains = [grain ] + firstNeighbours
495
+
496
+ secondNeighbours = []
497
+ for firstNeighbour in firstNeighbours :
498
+ trialSecondNeighbours = list (
499
+ self .neighbourNetwork .neighbors (firstNeighbour )
500
+ )
501
+ for secondNeighbour in trialSecondNeighbours :
502
+ if (secondNeighbour not in highlightGrains and
503
+ secondNeighbour not in secondNeighbours ):
504
+ secondNeighbours .append (secondNeighbour )
505
+ highlightGrains .extend (secondNeighbours )
506
+
507
+ highlightGrains = [grain .grainID for grain in highlightGrains ]
508
+ highlightColours = ['white' ]
509
+ highlightColours .extend (['yellow' ] * len (firstNeighbours ))
510
+ highlightColours .append ('green' )
511
+
512
+ # update the grain highlights layer in the plot
513
+ plot .addGrainHighlights (highlightGrains , grainColours = highlightColours )
495
514
496
515
@property
497
516
def proxigram (self ):
@@ -673,8 +692,8 @@ def plotGrainDataMap(
673
692
IDs of grains to plot for. Use -1 for all grains in the map.
674
693
bg: int or real, optional
675
694
Value to fill the background with.
676
- kwargs:
677
- Other parameters are passed to :func:`defdap.plotting.MapPlot.create`
695
+ kwargs : dict, optional
696
+ Keyword arguments passed to :func:`defdap.plotting.MapPlot.create`
678
697
679
698
Returns
680
699
-------
@@ -710,18 +729,18 @@ def plotGrainDataIPF(
710
729
711
730
Parameters
712
731
----------
713
- mapData : numpy.ndarray
714
- Array of map data to grain average. This must be cropped!
715
732
direction : numpy.ndarray
716
733
Vector of reference direction for the IPF.
717
- plotColourBar : bool, optional
718
- Set to False to exclude the colour bar from the plot.
719
- vmin : float, optional
720
- Minimum value of colour scale.
721
- vmax : float, optional
722
- Maximum value for colour scale.
723
- cLabel : str, optional
724
- Colour bar label text.
734
+ mapData : numpy.ndarray
735
+ Array of map data. This must be cropped! Either mapData or
736
+ grainData must be supplied.
737
+ grainData : list or np.array, optional
738
+ Grain values. This an be a single value per grain or RGB
739
+ values. You must supply either mapData or grainData.
740
+ grainIds: list of int or int, optional
741
+ IDs of grains to plot for. Use -1 for all grains in the map.
742
+ kwargs : dict, optional
743
+ Keyword arguments passed to :func:`defdap.quat.Quat.plotIPF`
725
744
726
745
"""
727
746
# Set default plot parameters then update with any input
@@ -759,6 +778,16 @@ def plotGrainDataIPF(
759
778
class Grain (object ):
760
779
"""
761
780
Base class for a grain.
781
+
782
+ Attributes
783
+ ----------
784
+ grainID : int
785
+
786
+ ownerMap : defdap.base.Map
787
+
788
+ coordList : list of tuples
789
+
790
+
762
791
"""
763
792
def __init__ (self , grainID , ownerMap ):
764
793
# list of coords stored as tuples (x, y). These are coords in a
@@ -861,7 +890,7 @@ def plotOutline(self, ax=None, plotScaleBar=False, **kwargs):
861
890
plotScaleBar : bool
862
891
plots the scale bar on the grain if true.
863
892
kwargs : dict
864
- keyword arguments to pass to :func:`defdap.plotting.GrainPlot.addMap`.
893
+ keyword arguments passed to :func:`defdap.plotting.GrainPlot.addMap`
865
894
866
895
Returns
867
896
-------
@@ -1014,14 +1043,8 @@ def plotGrainData(self, mapData=None, grainData=None, **kwargs):
1014
1043
grainData : numpy.ndarray
1015
1044
List of data at each point in the grain. Either this or
1016
1045
'mapData' must be supplied and 'grainData' takes precedence.
1017
- vmin : float, optional
1018
- Minimum value of colour scale.
1019
- vmax : float, optional
1020
- Minimum value of colour scale.
1021
- cLabel : str, optional
1022
- Colour bar label text.
1023
- cmap : str, optional
1024
- Colour map to use, default is viridis.
1046
+ kwargs : dict, optional
1047
+ Keyword arguments passed to :func:`defdap.plotting.GrainPlot.create`
1025
1048
1026
1049
"""
1027
1050
# Set default plot parameters then update with any input
0 commit comments