class_docstr: Animates a single line.
  
  Accepts additional keyword arguments to be passed to
  :meth:`matplotlib.axes.Axes.plot`.
  
  Parameters
  ----------
  x : 1D numpy array, list of 1D numpy arrays or a 2D numpy array, optional
      The x data to be animated. If 1D then will be constant over animation.
  y : list of 1D numpy arrays or a 2D numpy array
      The y data to be animated.
  ax : matplotlib.axes.Axes, optional
      The matplotlib axes to attach the block to.
      Defaults to matplotlib.pyplot.gca()
  t_axis : int, optional
      The axis of the numpy array that represents time.
      Defaults to 0. No effect if x, y are lists of numpy arrays.
  
      The default is chosen to be consistent with:
          X, T = numpy.meshgrid(x, t)
  **kwargs
      Passed on to `matplotlib.axes.Axes.plot`.
  
  Attributes
  ----------
  line: matplotlib.lines.Line2D
  
  ax : matplotlib.axes.Axes
      The matplotlib axes that the block is attached to.
  
  Notes
  -----
  This block animates a single line - to animate multiple lines you must call
  this once for each line, and then animate all of the blocks returned by
  passing a list of those blocks to `animatplot.Animation`.
class_docstr_tok: ["Animates","a","single","line",".","Accepts","additional","keyword","arguments","to","be","passed","to",":","meth",":","`","matplotlib.axes.Axes.plot","`",".","Parameters","--","--","--","--","--","x",":","1D","numpy","array",",","list","of","1D","numpy","arrays","or","a","2D","numpy","array",",","optional","The","x","data","to","be","animated",".","If","1D","then","will","be","constant","over","animation",".","y",":","list","of","1D","numpy","arrays","or","a","2D","numpy","array","The","y","data","to","be","animated",".","ax",":","matplotlib.axes.Axes",",","optional","The","matplotlib","axes","to","attach","the","block","to",".","Defaults","to","matplotlib.pyplot.gca","(",")","t_axis",":","int",",","optional","The","axis","of","the","numpy","array","that","represents","time",".","Defaults","to","0",".","No","effect","if","x",",","y","are","lists","of","numpy","arrays",".","The","default","is","chosen","to","be","consistent","with",":","X",",","T","=","numpy.meshgrid","(","x",",","t",")","*","*","kwargs","Passed","on","to","`","matplotlib.axes.Axes.plot","`",".","Attributes","--","--","--","--","--","line",":","matplotlib.lines.Line2D","ax",":","matplotlib.axes.Axes","The","matplotlib","axes","that","the","block","is","attached","to",".","Notes","--","--","-","This","block","animates","a","single","line","-","to","animate","multiple","lines","you","must","call","this","once","for","each","line",",","and","then","animate","all","of","the","blocks","returned","by","passing","a","list","of","those","blocks","to","`","animatplot.Animation","`","."]
code: def __init__(self, *args, ax=None, t_axis=0, **kwargs):
      super().__init__(ax, t_axis)
  
      if len(args) == 1:
          y = args[0]
          x = None
      elif len(args) == 2:
          [x, y] = args
      else:
          raise ValueError("Invalid data arguments to Line block")
  
      if y is None:
          raise ValueError("Must supply y data to plot")
      y = np.asanyarray(y)
      if str(y.dtype) == "object":
          self.t_axis = 0
  
          # ragged array
          if x is None:
              raise ValueError(
                  "Must specify x data explicitly when passing"
                  "a ragged array for y data"
              )
  
          x = np.asanyarray(x)
  
          if not all(
              len(xline) == len(yline) for xline, yline in zip(x, y)
          ):
              raise ValueError(
                  "Length of x & y data must match one another "
                  "for every frame"
              )
  
          self._is_list = True
  
      else:
          # Rectangular data
          if y.ndim != 2:
              raise ValueError("y data must be 2-dimensional")
  
          # x is optional
          shape = list(y.shape)
          shape.remove(y.shape[t_axis])
          (data_length,) = shape
          if x is None:
              x = np.arange(data_length)
          else:
              x = np.asanyarray(x)
  
          shape_mismatch = (
              "The dimensions of x must be compatible with "
              "those of y, but the shape of x is {} and the "
              "shape of y is {}".format(x.shape, y.shape)
          )
          if x.ndim == 1:
              # x is constant over time
              if len(x) == data_length:
                  # Broadcast x to match y
                  x = np.expand_dims(x, axis=t_axis)
                  x = np.repeat(x, repeats=y.shape[t_axis], axis=t_axis)
              else:
                  raise ValueError(shape_mismatch)
          elif x.ndim == 2:
              if x.shape != y.shape:
                  raise ValueError(shape_mismatch)
          else:
              raise ValueError("x, must be either 1- or 2-dimensional")
  
      self.x = x
      self.y = y
  
      frame_slice = self._make_slice(i=0, dim=2)
  
      x_first_frame_data = self.x[frame_slice]
      y_first_frame_data = self.y[frame_slice]
  
      (self.line,) = self.ax.plot(
          x_first_frame_data, y_first_frame_data, **kwargs
      )
  
file_path: animatplot/animatplot/blocks/lineplots.py
imports: import numpy
  from .base import Block
  from animatplot.util import parametric_line
label_desc: Use image node_id 1 to create a new Line object from inherited base classes: Block with example: obj = Line()