22diagnostics"""
33
44import numpy as np
5- import matplotlib
6- import matplotlib .pyplot as plt
7- import matplotlib .gridspec as gridspec
8- import matplotlib .patheffects as path_effects
95import scipy .constants as ct
106
117import aptools .data_analysis .beam_diagnostics as bd
@@ -28,6 +24,8 @@ def phase_space_overview_from_file(
2824
2925def phase_space_overview (x , y , z , px , py , pz , q , rasterized_scatter = None ,
3026 show = True ):
27+ import matplotlib .pyplot as plt
28+ import matplotlib .patheffects as path_effects
3129 em_x = bd .normalized_transverse_rms_emittance (x , px , w = q ) * 1e6
3230 em_y = bd .normalized_transverse_rms_emittance (y , py , w = q ) * 1e6
3331 a_x , b_x , g_x = bd .twiss_parameters (x , px , pz , w = q )
@@ -127,6 +125,9 @@ def slice_analysis(x, y, z, px, py, pz, q, n_slices=50, len_slice=None,
127125 ene_bins = 50 , left = 0.125 , right = 0.875 , top = 0.98 , bottom = 0.13 ,
128126 xlim = None , ylim = None , add_labels = False , include_twiss = False ,
129127 fig = None , rasterized_scatter = None , show = True ):
128+ import matplotlib .pyplot as plt
129+ import matplotlib .gridspec as gridspec
130+ from matplotlib .colorbar import Colorbar
130131 # analyze beam
131132 current_prof , z_edges = bd .current_profile (z , q , n_slices = n_slices ,
132133 len_slice = len_slice )
@@ -283,7 +284,7 @@ def slice_analysis(x, y, z, px, py, pz, q, n_slices=50, len_slice=None,
283284
284285 # colorbar
285286 ax = plt .subplot (gs [1 ])
286- matplotlib . colorbar . Colorbar (ax , pscatt , label = 'Q [fC]' )
287+ Colorbar (ax , pscatt , label = 'Q [fC]' )
287288
288289 # slice parameters plot
289290 plt .subplot (gs [2 ])
@@ -360,6 +361,9 @@ def energy_vs_z(
360361 xlim = None , ylim = None , show_text = True , x_proj = True , y_proj = True ,
361362 cbar = True , cbar_width = 0.02 , left = 0.125 , right = 0.875 , top = 0.98 ,
362363 bottom = 0.13 , fig = None , rasterized_scatter = None , show = True ):
364+ import matplotlib .pyplot as plt
365+ import matplotlib .gridspec as gridspec
366+ from matplotlib .colorbar import Colorbar
363367 # analyze beam
364368 current_prof , z_edges = bd .current_profile (z , q , n_slices = n_slices ,
365369 len_slice = len_slice )
@@ -488,13 +492,16 @@ def energy_vs_z(
488492 # colorbar
489493 if cbar :
490494 ax = plt .subplot (gs [1 ])
491- matplotlib . colorbar . Colorbar (ax , pscatt , label = 'Q [fC]' )
495+ Colorbar (ax , pscatt , label = 'Q [fC]' )
492496
493497 if show :
494498 plt .show ()
495499
496500
497501def full_phase_space (x , y , z , px , py , pz , q , show = True , ** kwargs ):
502+ import matplotlib .pyplot as plt
503+ import matplotlib .gridspec as gridspec
504+
498505 fig = plt .figure (figsize = (12 , 3 ))
499506 grid = gridspec .GridSpec (1 , 3 , figure = fig , wspace = 0.55 )
500507 hor_phase_space (
@@ -654,6 +661,8 @@ def phase_space_plot(
654661 s = 1 , cmap = 'plasma' , center_lines = False ,
655662 text = None , cbar = True , cbar_ticks = 3 , cbar_width = 0.05 ,
656663 subplot_spec = None , fig = None , tight_layout = False , show = True ):
664+ import matplotlib .pyplot as plt
665+ import matplotlib .gridspec as gridspec
657666
658667 if cbar :
659668 n_cols = 2
0 commit comments