@@ -175,7 +175,7 @@ def plot_distance(self, min_d=0.65, max_d=3.20, labels=None,
175175 axs [i ].hist (dist [site ]['dist' ], range = ranges ,
176176 bins = int ((ranges [1 ] - ranges [0 ]) / step ))
177177 axs [i ].set (ylabel = 'n. Atoms' )
178- axs [- 1 ].set (xlabel = '$\AA$' )
178+ axs [- 1 ].set (xlabel = r '$\AA$' )
179179 if len (dist ) > 1 :
180180 for ax in axs .flat :
181181 ax .label_outer ()
@@ -955,7 +955,86 @@ def plot_3Dlattice(self,q_max=4.0,x_axis=[1,0,0],y_axis=[0,1,0],centre=[0,0,0],c
955955 ax .set_zlim3d (- q_max , q_max )
956956
957957 fp .labels (self .xtl .name ,'Qx' ,'Qy' ,'Qz' )
958-
958+
959+ def plot_3Dintensity (self , q_max = 4.0 , central_hkl = (0 , 0 , 0 ), show_forbidden = False ):
960+ """
961+ Plot Reciprocal Space lattice points in 3D, with point size and colour based on the intensity
962+ """
963+ from matplotlib .colors import Normalize
964+
965+ # Generate lattice of reciprocal space points
966+ hmax , kmax , lmax = fc .maxHKL (q_max , self .xtl .Cell .UVstar ())
967+ HKL = fc .genHKL ([hmax , - hmax ], [kmax , - kmax ], [lmax , - lmax ])
968+ HKL = HKL + central_hkl # reflection about central reflection
969+ Q = self .xtl .Cell .calculateQ (HKL )
970+ intensity = self .xtl .Scatter .intensity (HKL )
971+ reflections = intensity > 0.1
972+ extinctions = intensity < 0.1
973+
974+ # Create plot
975+ fig = plt .figure (figsize = self ._figure_size , dpi = self ._figure_dpi )
976+ ax = fig .add_subplot (111 , projection = '3d' )
977+
978+ # Create cell box
979+ uvw = np .array ([[0. , 0 , 0 ], [1 , 0 , 0 ], [1 , 0 , 1 ], [1 , 1 , 1 ], [1 , 1 , 0 ], [0 , 1 , 0 ], [0 , 1 , 1 ],
980+ [0 , 0 , 1 ], [1 , 0 , 1 ], [1 , 0 , 0 ], [1 , 1 , 0 ], [1 , 1 , 1 ], [0 , 1 , 1 ], [0 , 1 , 0 ], [0 , 0 , 0 ],
981+ [0 , 0 , 1 ]])
982+ bpos = self .xtl .Cell .calculateQ (uvw + central_hkl )
983+ ax .plot (bpos [:, 0 ], bpos [:, 1 ], bpos [:, 2 ], '-' , c = 'k' ) # cell box
984+ fp .plot_arrow (bpos [[0 , 1 ], 0 ], bpos [[0 , 1 ], 1 ], bpos [[0 , 1 ], 2 ], col = 'r' , width = 4 , arrow_size = 10 ) # a*
985+ fp .plot_arrow (bpos [[0 , 5 ], 0 ], bpos [[0 , 5 ], 1 ], bpos [[0 , 5 ], 2 ], col = 'g' , width = 4 , arrow_size = 10 ) # b*
986+ fp .plot_arrow (bpos [[0 , 7 ], 0 ], bpos [[0 , 7 ], 1 ], bpos [[0 , 7 ], 2 ], col = 'b' , width = 4 , arrow_size = 10 ) # c*
987+
988+ cmap = plt .get_cmap ('hot_r' )
989+ vmin , vmax = 0 , np .median (intensity [intensity > 0.1 ])
990+
991+ norm_intensity = intensity / intensity .max ()
992+ # colours = cmap(norm_intensity)
993+ norm = Normalize (vmin = vmin , vmax = vmax )
994+ max_point_size = 500
995+ sizes = max_point_size * norm_intensity
996+
997+ # Reflections
998+ sct = ax .scatter (Q [reflections ,0 ], Q [reflections ,1 ], Q [reflections ,2 ],
999+ c = intensity [reflections ], s = sizes [reflections ],
1000+ marker = 'o' , cmap = cmap , norm = norm )
1001+ # Extinctions
1002+ if show_forbidden :
1003+ ax .scatter (Q [extinctions ,0 ], Q [extinctions ,1 ], Q [extinctions ,2 ], marker = 'x' , c = 'k' , s = 20 )
1004+
1005+ cx , cy , cz = self .xtl .Cell .calculateQ (central_hkl ).squeeze ()
1006+ ax .set_xlim3d (cx - 2 * q_max , cx + 2 * q_max )
1007+ ax .set_ylim3d (cy - 2 * q_max , cy + 2 * q_max )
1008+ ax .set_zlim3d (cz - 2 * q_max , cz + 2 * q_max )
1009+
1010+ fp .labels (self .xtl .name , 'Qx' , 'Qy' , 'Qz' )
1011+ plt .colorbar (sct , label = 'intensity' )
1012+
1013+ def plot_intensity_histogram (self , q_max = 4.0 ):
1014+ """
1015+ Plot histogram of intensity of reflections
1016+ """
1017+ # Generate lattice of reciprocal space points
1018+ hmax , kmax , lmax = fc .maxHKL (q_max , self .xtl .Cell .UVstar ())
1019+ HKL = fc .genHKL ([hmax , - hmax ], [kmax , - kmax ], [lmax , - lmax ])
1020+ # HKL = HKL + centre # reflection about central reflection
1021+ Q = self .xtl .Cell .calculateQ (HKL )
1022+ qmag = fg .mag (Q )
1023+ intensity = self .xtl .Scatter .intensity (HKL )
1024+
1025+ n_bins = 100 if len (qmag ) > 100 else len (qmag )
1026+ log_bins = np .logspace (0 , np .log10 (intensity .max ()), n_bins )
1027+
1028+ fig = plt .figure (figsize = self ._figure_size , dpi = self ._figure_dpi )
1029+ ax = fig .add_subplot (111 )
1030+ # ax.hist(np.log10(intensity[intensity > 0]), bins=log_bins)
1031+ ax .hist (np .log10 (intensity + 1 ), bins = log_bins )
1032+ ax .set_xscale ('log' )
1033+ ax .set_xlabel ('intensity' )
1034+ ax .set_ylabel ('Count' )
1035+ ax .set_title (self .xtl .name )
1036+
1037+
9591038 def quick_intensity_cut (self ,x_axis = [1 ,0 ,0 ],y_axis = [0 ,1 ,0 ],centre = [0 ,0 ,0 ], q_max = 4.0 ,cut_width = 0.05 ):
9601039 """
9611040 Plot a cut through reciprocal space, visualising the intensity as different sized markers
0 commit comments