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))
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(*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())
def plotcf2d(x, y, z, darken=None, axes=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. """ xmin = real(x).min() xmax = real(x).max() ymin = real(y).min() ymax = real(y).max() extent = [xmin, xmax, ymin, ymax] kw = { 'extent': extent, 'origin': 'lower', '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 axes.imshow(color_map(z, darken=darken), **kw)
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)
def plotcf2d(x, y, z, darken=None, axes=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. """ xmin = real(x).min() xmax = real(x).max() ymin = real(y).min() ymax = real(y).max() extent = [xmin, xmax, ymin, ymax] kw = {'extent': extent, 'origin': 'lower', '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 axes.imshow(color_map(z, darken=darken), **kw)
def path_cost(self, cost_so_far, A, action, B): #print "A",A," to B",B," = ", self.graph.get(A,B)," + ", cost_so_far total_cost = cost_so_far + (self.graph.get(A,B) or float('inf')) if (self.cost_values[B[0]][B[1]] > total_cost): value = total_cost if (value > 255): value = 255 color = color_map(value) #print color self.costs[B[0]][B[1]][0] = color[0]*255 self.costs[B[0]][B[1]][1] = color[1]*255 self.costs[B[0]][B[1]][2] = color[2]*255 return total_cost
def path_cost(self, cost_so_far, A, action, B): #print "A",A," to B",B," = ", self.graph.get(A,B)," + ", cost_so_far total_cost = cost_so_far + (self.graph.get(A,B) or infinity) if (self.cost_values[B[0]][B[1]] > total_cost): value = total_cost if (value > 255): value = 255 color = color_map(value) #print color self.costs[B[0]][B[1]][0] = color[0]*255 self.costs[B[0]][B[1]][1] = color[1]*255 self.costs[B[0]][B[1]][2] = color[2]*255 return total_cost
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)
def stemcf(grid, phase, modulus, darken=False, axes=None, linestylep="solid", linewidthp=2, color=None, markerp="o", **kwargs): r""" Stemplot the modulus of a complex valued function :math:`f:I \rightarrow 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 stemmed markers. :param markerp: The shape of the stemmed markers. .. note:: Additional keyword arguments are passe to the plot function. """ # 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)
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": "nearest", "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 i = where((xmin <= x) & (x <= xmax))[0] j = where((ymin <= y) & (y <= ymax))[0] I, J = meshgrid(i, j) # Color code and plot the data axes.imshow(color_map(z[I, J], darken=darken), **kw)
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. @keyword darken: Whether to take into account the modulus of the data to darken colors. @keyword axes: The axes instance used for plotting. @note: Additional keyword arguments are passe 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))
def stemcf(grid, phase, modulus, darken=False, 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 passe 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)