class_docstr: Lexical dispersion illustrates the homogeneity of a word (or set of words) across
  the documents of a corpus.
  
  DispersionPlot allows for visualization of the lexical dispersion of words in a
  corpus. This plot illustrates with vertical lines the occurrences of one or more
  search terms throughout the corpus, noting how many words relative to the beginning
  of the corpus it appears. If the target vector of the corpus documents is provided,
  the points will be colored with respect to their document category, which allows for
  additional analysis of relationships in search term homogeneity within and across
  document categories. If annotation is requested, document boundaries will be
  displayed as vertical lines in the plot.
  
  Parameters
  ----------
  search_terms : list
      A list of search terms whose dispersion across a corpus passed at fit
      should be visualized.
  
  ax : matplotlib axes, default: None
      The axes to plot the figure on.
  
  colors : list or tuple of colors
      Specify the colors for each individual class. Will override colormap if both are
      provided.
  
  colormap : string or matplotlib cmap
      Qualitative colormap for discrete target
  
  ignore_case : boolean, default: False
      Specify whether input will be case-sensitive.
  
  annotate_docs : boolean, default: False
      Specify whether document boundaries will be displayed. Vertical lines
      are positioned at the end of each document.
  
  labels : list of strings
      The names of the classes in the target, used to create a legend.
      Labels must match names of classes in sorted order.
  
  kwargs : dict
      Pass any additional keyword arguments to the super class.
  
  Attributes
  ----------
  self.classes_ : list
      A list of strings representing the unique classes in the target in sorted order.
      If ``y`` is provided, these are extracted from ``y``, unless a list of class
      labels is provided by the user on instantiation.
  
  self.boundaries_ : list
      A list of integers indicating the document boundaries with respect to
      word offsets.
  
  self.indexed_words_ : list
      A list of integers indicating the y position for each occurrence of each of
      the search terms.
  
  self.word_categories_ : list
      A list of strings indicating the corresponding document category of each search
      term occurrence.
class_docstr_tok: ["Lexical","dispersion","illustrates","the","homogeneity","of","a","word","(","or","set","of","words",")","across","the","documents","of","a","corpus",".","DispersionPlot","allows","for","visualization","of","the","lexical","dispersion","of","words","in","a","corpus",".","This","plot","illustrates","with","vertical","lines","the","occurrences","of","one","or","more","search","terms","throughout","the","corpus",",","noting","how","many","words","relative","to","the","beginning","of","the","corpus","it","appears",".","If","the","target","vector","of","the","corpus","documents","is","provided",",","the","points","will","be","colored","with","respect","to","their","document","category",",","which","allows","for","additional","analysis","of","relationships","in","search","term","homogeneity","within","and","across","document","categories",".","If","annotation","is","requested",",","document","boundaries","will","be","displayed","as","vertical","lines","in","the","plot",".","Parameters","--","--","--","--","--","search_terms",":","list","A","list","of","search","terms","whose","dispersion","across","a","corpus","passed","at","fit","should","be","visualized",".","ax",":","matplotlib","axes",",","default",":","None","The","axes","to","plot","the","figure","on",".","colors",":","list","or","tuple","of","colors","Specify","the","colors","for","each","individual","class",".","Will","override","colormap","if","both","are","provided",".","colormap",":","string","or","matplotlib","cmap","Qualitative","colormap","for","discrete","target","ignore_case",":","boolean",",","default",":","False","Specify","whether","input","will","be","case-sensitive",".","annotate_docs",":","boolean",",","default",":","False","Specify","whether","document","boundaries","will","be","displayed",".","Vertical","lines","are","positioned","at","the","end","of","each","document",".","labels",":","list","of","strings","The","names","of","the","classes","in","the","target",",","used","to","create","a","legend",".","Labels","must","match","names","of","classes","in","sorted","order",".","kwargs",":","dict","Pass","any","additional","keyword","arguments","to","the","super","class",".","Attributes","--","--","--","--","--","self.classes_",":","list","A","list","of","strings","representing","the","unique","classes","in","the","target","in","sorted","order",".","If","``","y","``","is","provided",",","these","are","extracted","from","``","y","``",",","unless","a","list","of","class","labels","is","provided","by","the","user","on","instantiation",".","self.boundaries_",":","list","A","list","of","integers","indicating","the","document","boundaries","with","respect","to","word","offsets",".","self.indexed_words_",":","list","A","list","of","integers","indicating","the","y","position","for","each","occurrence","of","each","of","the","search","terms",".","self.word_categories_",":","list","A","list","of","strings","indicating","the","corresponding","document","category","of","each","search","term","occurrence","."]
docstr: Produces a generator containing the offset word count, y_coordinate, and
  label/category for each occurrance of the search terms.
  
  Attributes
  ----------
  self.boundaries_ : list
      A list of integers indicating the document boundaries with respect to
      word offsets.
docstr_tok: ["Produces","a","generator","containing","the","offset","word","count",",","y_coordinate",",","and","label\/category","for","each","occurrance","of","the","search","terms",".","Attributes","--","--","--","--","--","self.boundaries_",":","list","A","list","of","integers","indicating","the","document","boundaries","with","respect","to","word","offsets","."]
code: def _compute_dispersion(self, X, y):
      """
      Produces a generator containing the offset word count, y_coordinate, and
      label/category for each occurrance of the search terms.
  
      Attributes
      ----------
      self.boundaries_ : list
          A list of integers indicating the document boundaries with respect to
          word offsets.
      """
      self.boundaries_ = []
      offset = 0
  
      if y is None:
          y = itertools.repeat(None)
  
      for doc, category in zip(X, y):
          for word in doc:
              if self.ignore_case:
                  word = word.lower()
  
              # NOTE: this will find all indices if duplicate words are supplied
              # In the case that word is not in target words, any empty list is
              # returned and no data will be yielded
              offset += 1
              for y_coord in (self.indexed_words_ == word).nonzero()[0]:
                  y_coord = int(y_coord)
                  yield (offset, y_coord, category)
  
          if self.annotate_docs:
              self.boundaries_.append(offset)
  
      self.boundaries_ = np.array(self.boundaries_, dtype=int)
  
file_path: yellowbrick/yellowbrick/text/dispersion.py
imports: import itertools
  from collections import defaultdict
  import numpy
  from yellowbrick.text.base import TextVisualizer
  from yellowbrick.style.colors import resolve_colors
  from yellowbrick.exceptions import YellowbrickValueError
label_desc: Use image node_id 2 for calling the DispersionPlot obj's underlying member method code with example usage: obj._compute_dispersion(X, y) without return types