code: def filter_margins_by_quantile(
      dist: Union[np.ndarray, pd.Series], margin_quantile_filter: float
  ) -> np.ndarray:
      """Filter the margins of the distribution by a quantile."""
      qt_min, qt_max = np.quantile(
          dist, [margin_quantile_filter, 1 - margin_quantile_filter]
      )
      return dist[(qt_max >= dist) & (dist >= qt_min)]
  
imports: from numbers import Number
  from typing import Dict, Optional, Tuple, Union
  import numpy
  import pandas
  from plotly.graph_objs import Figure
  from plotly.subplots import make_subplots
  from scipy.stats import chi2_contingency, wasserstein_distance
  from deepchecks.core import ConditionCategory, ConditionResult
  from deepchecks.core.errors import DeepchecksValueError, NotEnoughSamplesError
  from deepchecks.utils.dict_funcs import get_dict_entry_by_value
  from deepchecks.utils.distribution.plot import CategoriesSortingKind, drift_score_bar_traces, feature_distribution_traces
  from deepchecks.utils.distribution.preprocessing import preprocess_2_cat_cols_to_same_bins
  from deepchecks.utils.plot import DEFAULT_DATASET_NAMES
  from deepchecks.utils.strings import format_number
label_desc: Use image node_id 1 for calling a global function with example usage: filter_margins_by_quantile(dist, margin_quantile_filter) and returns: dist