Exemple #1
0
def plotcf(grid, phase, modulus, darken=None, axes=None, linestylep="solid", linewidthp=1, color="k", **kwargs):
    r"""Plot the modulus of a complex valued function
    :math:`f:\mathbb{R} \rightarrow \mathbb{C}`
    together with its phase in a color coded fashion.

    :param grid: The grid nodes of the real domain R
    :param phase: The phase of the complex domain result f(grid)
    :param modulus: The modulus of the complex domain result f(grid)
    :param darken: Whether to take into account the modulus of the data to darken colors.
    :param axes: The axes instance used for plotting.
    :param linestylep: The line style of the phase curve.
    :param linewidthp: The line width of the phase curve.
    :param color: The color of the phase curve.
    """
    # Color mapping
    rgb_colors = color_map(modulus, phase=phase, modulus=modulus, darken=darken)

    # Put all the vertical line into a collection
    segments = [array([[node, 0], [node, value]]) for node, value in zip(grid, modulus)]
    line_segments = LineCollection(segments)

    # Set some properties of the lines
    rgb_colors = line_segments.to_rgba(rgb_colors)
    line_segments.set_color(rgb_colors[0])
    line_segments.set_linestyle(linestylep)
    line_segments.set_linewidth(linewidthp)

    # Plot to the given axis instance or retrieve the current one
    if axes is None:
        axes = gca()

    # Plot the phase
    axes.add_collection(line_segments)
    # Plot the modulus
    axes.plot(grid, modulus, color=color, **kwargs)
Exemple #2
0
def stemcf3d(gridu, gridv, phase, modulus, darken=None, fig=None, markerp="o", **kwargs):
    r"""Stemplot the modulus of a complex valued function :math:`f:I\times I -> \mathbb{C}` together with its
    phase in a color coded fashion. Additional keyword arguments are passed to the plot function.

    :param gridu: The x components of the grid nodes of the real domain grid :math:`\Gamma`
    :param gridv: The y components of the grid nodes of the real domain grid :math:`\Gamma`
    :param phase: The phase of the complex domain result :math:`f(\Gamma)`
    :param modulus: The modulus of the complex domain result :math:`f(\Gamma)`
    :param darken: Whether to take into account the modulus of the data to darken colors.
    :param fig: The figure instance used for plotting.
    :param markerp: The shape of the stemmed markers.
    """
    # Color mapping
    rgb_colors = squeeze(color_map(gridv, phase=phase, modulus=modulus, darken=darken))

    # Plot to the given axis instance or retrieve the current one
    if fig is None:
        fig = gcf()

    axes = fig.add_subplot(1, 1, 1, projection='3d')

    for ui, vi, wi, col in zip(gridu, gridv, modulus, rgb_colors):
        line = art3d.Line3D(*list(zip((ui, vi, 0), (ui, vi, wi))), marker=markerp, markevery=(1, 1), color=col)
        axes.add_line(line)

    axes.set_xlim3d(real(gridu).min(), real(gridu).max())
    axes.set_ylim3d(real(gridv).min(), real(gridv).max())
    axes.set_zlim3d(real(modulus).min(), real(modulus).max())
Exemple #3
0
def plotcm(matrix, phase=None, modulus=None, darken=None, axes=None, **kwargs):
    """Plot complex matrices with the phase of the entries encoded into the usual color code.

    :param matrix: The matrix data.
    :param phase: The phase of the entries, if not given they are computed.
    :param modulus: The modulus of the entries, if not given they are computed.
    :param darken: Whether to take into account the modulus of the data to darken colors.
    :param axes: The axes instance used for plotting.

    Note that the additional keyword arguments are passed to the plot function.
    """
    # TODO: Allow to specify axes

    nr, nc = matrix.shape
    extent = [-0.5, nc - 0.5, nr - 0.5, -0.5]

    kw = {'extent': extent,
          'origin': 'upper',
          'interpolation': 'nearest',
          'aspect': 'equal'}
    kw.update(kwargs)

    # Plot to the given axis instance or retrieve the current one
    if axes is None:
        axes = gca()

    # Color code and plot the data matrix
    axes.imshow(color_map(matrix, phase=phase, modulus=modulus, darken=darken), **kw)

    axes.xaxis.tick_top()
    axes.xaxis.set_ticks_position('both')
    axes.xaxis.set_major_locator(ticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10], integer=True))
    axes.yaxis.set_major_locator(ticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10], integer=True))
Exemple #4
0
def plotcf(grid,
           phase,
           modulus,
           darken=None,
           axes=None,
           linestylep="solid",
           linewidthp=1,
           color="k",
           **kwargs):
    r"""Plot the modulus of a complex valued function
    :math:`f:\mathbb{R} \rightarrow \mathbb{C}`
    together with its phase in a color coded fashion.

    :param grid: The grid nodes of the real domain R
    :param phase: The phase of the complex domain result f(grid)
    :param modulus: The modulus of the complex domain result f(grid)
    :param darken: Whether to take into account the modulus of the data to darken colors.
    :param axes: The axes instance used for plotting.
    :param linestylep: The line style of the phase curve.
    :param linewidthp: The line width of the phase curve.
    :param color: The color of the phase curve.
    """
    # Color mapping
    rgb_colors = color_map(modulus,
                           phase=phase,
                           modulus=modulus,
                           darken=darken)

    # Put all the vertical line into a collection
    segments = [
        array([[node, 0], [node, value]])
        for node, value in zip(grid, modulus)
    ]
    line_segments = LineCollection(segments)

    # Set some properties of the lines
    rgb_colors = line_segments.to_rgba(rgb_colors)
    line_segments.set_color(rgb_colors[0])
    line_segments.set_linestyle(linestylep)
    line_segments.set_linewidth(linewidthp)

    # Plot to the given axis instance or retrieve the current one
    if axes is None:
        axes = gca()

    # Plot the phase
    axes.add_collection(line_segments)
    # Plot the modulus
    axes.plot(grid, modulus, color=color, **kwargs)
Exemple #5
0
def plotcf2d(x, y, z, darken=None, axes=None, limits=None, **kwargs):
    r"""Plot complex valued functions :math:`\mathbb{R}^2 \rightarrow \mathbb{C}`
    with the usual color code.

    :param x: The :math:`x` values.
    :param x: The :math:`y` values.
    :param z: The values :math:`z = f(x,y)`.
    :param darken: How strong to take into account the modulus of the data to darken colors.
                   Values with :math:`|z| = R` will get fully saturated colors
                   while :math:`|z| = 0` is black and :math:`|z| \rightarrow \infty`
                   get whiter and whiter.
    :type darken: Float or ``None`` to disable darkening of colors. Default is :math:`R = 1.0`.
    :param axes: The axes instance used for plotting.
    """
    if limits is None:
        xmin = real(x).min()
        xmax = real(x).max()
        ymin = real(y).min()
        ymax = real(y).max()
        extent = [xmin, xmax, ymin, ymax]
    else:
        xmin = limits[0]
        xmax = limits[1]
        ymin = limits[2]
        ymax = limits[3]
        extent = [xmin, xmax, ymin, ymax]

    kw = {'extent': extent,
          'origin': 'lower',
          'interpolation': 'bilinear',
          'aspect': 'equal'}
    kw.update(kwargs)

    # Plot to the given axis instance or retrieve the current one
    if axes is None:
        axes = gca()

    # Region to cut out
    x = x.reshape(1, -1)
    y = y.reshape(-1, 1)
    i = where((xmin <= x) & (x <= xmax))[1]
    j = where((ymin <= y) & (y <= ymax))[0]
    I, J = meshgrid(i, j)

    # Color code and plot the data
    axes.imshow(color_map(z[J, I], darken=darken), **kw)
Exemple #6
0
def stemcf(grid, phase, modulus, darken=None, axes=None, linestylep="solid", linewidthp=2, color=None, markerp="o", **kwargs):
    r"""Stemplot the modulus of a complex valued function :math:`f:I -> \mathbb{C}` together with its phase in a color coded fashion.
    Additional keyword arguments are passed to the plot function.

    :param grid: The grid nodes of the real domain grid :math:`\Gamma`
    :param phase: The phase of the complex domain result :math:`f(\Gamma)`
    :param modulus: The modulus of the complex domain result :math:`f(\Gamma)`
    :param darken: Whether to take into account the modulus of the data to darken colors.
    :param axes: The axes instance used for plotting.
    :param linestylep: The line style of the phase curve.
    :param linewidthp: The line width of the phase curve.
    :param color: The color of the stemmed markers.
    :param markerp: The shape of the stemmed markers.
    """
    # Color mapping
    rgb_colors = color_map(grid, phase=phase, modulus=modulus, darken=darken)

    # Put all the vertical line into a collection
    segments = [array([[node, 0], [node, value]]) for node, value in zip(grid, modulus)]
    line_segments = LineCollection(segments)

    # Set some properties of the lines
    rgb_colors = line_segments.to_rgba(rgb_colors)
    line_segments.set_color(rgb_colors[0])
    line_segments.set_linestyle(linestylep)
    line_segments.set_linewidth(linewidthp)

    # Plot to the given axis instance or retrieve the current one
    if axes is None:
        axes = gca()

    # Plot the phase
    axes.add_collection(line_segments)
    # Plot the modulus
    if color is None:
        # Scatter has a problem with complex data type, make sure values are purely real
        axes.scatter(grid, real(modulus), c=rgb_colors[0], **kwargs)
    else:
        axes.plot(grid, modulus, linestyle="", marker=markerp, color=color, **kwargs)
    # Plot the ground line
    axes.plot(grid, zeros(grid.shape), linestyle=linestylep, color="k", **kwargs)
Exemple #7
0
def plotcm(matrix, phase=None, modulus=None, darken=None, axes=None, **kwargs):
    """Plot complex matrices with the phase of the entries encoded into the usual color code.

    :param matrix: The matrix data.
    :param phase: The phase of the entries, if not given they are computed.
    :param modulus: The modulus of the entries, if not given they are computed.
    :param darken: Whether to take into account the modulus of the data to darken colors.
    :param axes: The axes instance used for plotting.

    Note that the additional keyword arguments are passed to the plot function.
    """
    # TODO: Allow to specify axes

    nr, nc = matrix.shape
    extent = [-0.5, nc - 0.5, nr - 0.5, -0.5]

    kw = {
        'extent': extent,
        'origin': 'upper',
        'interpolation': 'nearest',
        'aspect': 'equal'
    }
    kw.update(kwargs)

    # Plot to the given axis instance or retrieve the current one
    if axes is None:
        axes = gca()

    # Color code and plot the data matrix
    axes.imshow(color_map(matrix, phase=phase, modulus=modulus, darken=darken),
                **kw)

    axes.xaxis.tick_top()
    axes.xaxis.set_ticks_position('both')
    axes.xaxis.set_major_locator(
        ticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10], integer=True))
    axes.yaxis.set_major_locator(
        ticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10], integer=True))