Ticket #11028: trac-11028-modular-complex-plot.2.3.patch
File trac-11028-modular-complex-plot.2.3.patch, 8.9 KB (added by , 10 years ago) |
---|
-
sage/calculus/riemann.pyx
# HG changeset patch # User Ethan Van Andel <evlutte@gmail.com> # Date 1301066115 14400 # Node ID d24f5e4fe0d6900f13a80d0d02f65db89cab2bf4 # Parent bb710f96608348b0b53eab2ed55ec0190a2f1859 RiemannMap.plot_colored made to use the more modular ComplexPlot diff -r bb710f966083 -r d24f5e4fe0d6 sage/calculus/riemann.pyx
a b 40 40 41 41 from sage.gsl.interpolation import spline 42 42 43 from sage.plot.complex_plot import ComplexPlot 44 43 45 import numpy as np 44 46 cimport numpy as np 45 47 … … 102 104 EXAMPLES: 103 105 104 106 The unit circle identity map:: 105 106 sage: m = Riemann_Map([lambda t: e^(I*t)], [lambda t: I*e^(I*t)], 0) # long time (4 sec) 107 sage: f(t) = e^(I*t) 108 sage: fprime(t) = I*e^(I*t) 109 sage: m = Riemann_Map([f], [fprime], 0) # long time (4 sec) 107 110 108 111 The unit circle with a small hole:: 109 112 … … 111 114 sage: fprime(t) = I*e^(I*t) 112 115 sage: hf(t) = 0.5*e^(-I*t) 113 116 sage: hfprime(t) = 0.5*-I*e^(-I*t) 114 sage: m = Riemann_Map([f, hf], [ hf, hfprime], 0.5 + 0.5*I)117 sage: m = Riemann_Map([f, hf], [fprime, hfprime], 0.5 + 0.5*I) 115 118 116 119 A square:: 117 120 … … 340 346 sage: fprime(t) = I*e^(I*t) 341 347 sage: hf(t) = 0.5*e^(-I*t) 342 348 sage: hfprime(t) = 0.5*-I*e^(-I*t) 343 sage: m = Riemann_Map([f, hf], [ hf, hfprime], 0.5 + 0.5*I)349 sage: m = Riemann_Map([f, hf], [fprime, hfprime], 0.5 + 0.5*I) 344 350 345 351 Getting the szego for a specifc boundary:: 346 352 … … 765 771 comp_pt(temp, 0), rgbcolor=rgbcolor, pointsize=thickness) 766 772 return edge + sum(circle_list) + sum(line_list) 767 773 768 def plot_colored(self, plot_range=[], int plot_points=100): 774 @options(interpolation='catrom') 775 def plot_colored(self, plot_range=[], int plot_points=100, **options): 769 776 """ 770 777 Draws a colored plot of the Riemann map. A red point on the 771 778 colored plot corresponds to a red point on the unit disc. Note that … … 833 840 np.complex(xmin + 0.5*xstep + i*xstep, 834 841 ymin + 0.5*ystep + j*ystep)) 835 842 g = Graphics() 836 g.add_primitive(Co lorPlot(z_values, (xmin, xmax), (ymin, ymax)))843 g.add_primitive(ComplexPlot(complex_to_rgb(z_values), (xmin, xmax), (ymin, ymax),options)) 837 844 return g 838 845 839 846 cdef comp_pt(clist, loop=True): … … 879 886 880 887 EXAMPLES: 881 888 882 This tests it implicitly:: 883 884 sage: from sage.plot.complex_plot import complex_to_rgb 885 sage: complex_to_rgb([[0, 1, 10]]) 886 array([[[ 0. , 0. , 0. ], 887 [ 0.77172568, 0. , 0. ], 888 [ 1. , 0.22134776, 0.22134776]]]) 889 This tests it implicitly:: 890 891 sage: from sage.calculus.riemann import complex_to_rgb 892 sage: import numpy 893 sage: complex_to_rgb(numpy.array([[0, 1, 1000]],dtype = numpy.complex128)) 894 array([[[ 1., 1., 1.], 895 [ 1., 0., 0.], 896 [-998., 0., 0.]]]) 889 897 """ 890 898 return 1 - r 891 899 … … 890 891 return 1 - r 891 892 892 c def complex_to_rgb(np.ndarray z_values):893 r"""893 cpdef complex_to_rgb(np.ndarray z_values): 894 """ 894 895 Convert from an array of complex numbers to its corresponding matrix of 895 896 RGB values. … … 905 906 906 907 EXAMPLES:: 907 908 908 sage: from sage.plot.complex_plot import complex_to_rgb 909 sage: complex_to_rgb([[0, 1, 1000]]) 910 array([[[ 0. , 0. , 0. ], 911 [ 0.77172568, 0. , 0. ], 912 [ 1. , 0.64421177, 0.64421177]]]) 913 sage: complex_to_rgb([[0, 1j, 1000j]]) 914 array([[[ 0. , 0. , 0. ], 915 [ 0.38586284, 0.77172568, 0. ], 916 [ 0.82210588, 1. , 0.64421177]]]) 909 sage: from sage.calculus.riemann import complex_to_rgb 910 sage: import numpy 911 sage: complex_to_rgb(numpy.array([[0, 1, 1000]],dtype = numpy.complex128)) 912 array([[[ 1., 1., 1.], 913 [ 1., 0., 0.], 914 [-998., 0., 0.]]]) 915 sage: complex_to_rgb(numpy.array([[0, 1j, 1000j]],dtype = numpy.complex128)) 916 array([[[ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00], 917 [ 5.00000000e-01, 1.00000000e+00, 0.00000000e+00], 918 [ -4.99000000e+02, -9.98000000e+02, 0.00000000e+00]]]) 917 919 """ 918 920 cdef unsigned int i, j, imax, jmax 919 921 cdef double x, y, mag, arg … … 983 976 sig_off() 984 977 return rgb 985 978 986 class ColorPlot(GraphicPrimitive):987 """988 The GraphicsPrimitive to display complex functions in using the domain989 coloring method990 991 INPUT:992 993 - ``z_values`` -- An array of complex values to be plotted.994 995 - ``x_range`` -- A minimum and maximum x value for the plot.996 997 - ``y_range`` -- A minimum and maximum y value for the plot.998 999 EXAMPLES::1000 1001 sage: p = complex_plot(lambda z: z^2-1, (-2, 2), (-2, 2))1002 """1003 def __init__(self, z_values, x_range, y_range):1004 """1005 Setup a ``ColorPlot`` object.1006 1007 TESTS::1008 1009 sage: p = complex_plot(lambda z: z^2-1, (-2, 2), (-2, 2))1010 """1011 self.x_range = x_range1012 self.y_range = y_range1013 self.z_values = z_values1014 self.x_count = len(z_values)1015 self.y_count = len(z_values[0])1016 self.rgb_data = complex_to_rgb(z_values)1017 GraphicPrimitive.__init__(self, [])1018 1019 def get_minmax_data(self):1020 """1021 Returns a dictionary with the bounding box data.1022 1023 EXAMPLES::1024 1025 sage: p = complex_plot(lambda z: z, (-1, 2), (-3, 4))1026 sage: sorted(p.get_minmax_data().items())1027 [('xmax', 2.0), ('xmin', -1.0), ('ymax', 4.0), ('ymin', -3.0)]1028 """1029 from sage.plot.plot import minmax_data1030 return minmax_data(self.x_range, self.y_range, dict=True)1031 1032 def _allowed_options(self):1033 """1034 Return a dictionary of valid options for this ``ColorPlot`` object.1035 1036 TESTS::1037 1038 sage: isinstance(complex_plot(lambda z: z, (-1,1), (-1,1))[0]._allowed_options(), dict)1039 True1040 """1041 return {'plot_points': 'How many points to use for plotting precision',1042 'interpolation': 'What interpolation method to use'}1043 1044 def _repr_(self):1045 """1046 Return a string representation of this ``ColorPlot`` object.1047 1048 TESTS::1049 1050 sage: isinstance(complex_plot(lambda z: z, (-1,1), (-1,1))[0]._repr_(), str)1051 True1052 """1053 return "ColorPlot defined by a %s x %s data grid" % (1054 self.x_count, self.y_count)1055 1056 def _render_on_subplot(self, subplot):1057 """1058 Render the graphics object on a subplot.1059 1060 TESTS::1061 1062 sage: complex_plot(lambda x: x^2, (-5, 5), (-5, 5))1063 """1064 options = self.options()1065 x0, x1 = float(self.x_range[0]), float(self.x_range[1])1066 y0, y1 = float(self.y_range[0]), float(self.y_range[1])1067 subplot.imshow(self.rgb_data, origin='lower',1068 extent=(x0,x1,y0,y1), interpolation='catrom') -
sage/plot/complex_plot.pyx
diff -r bb710f966083 -r d24f5e4fe0d6 sage/plot/complex_plot.pyx
a b 164 164 return rgb 165 165 166 166 class ComplexPlot(GraphicPrimitive): 167 def __init__(self, z_values, xrange, yrange, options): 167 """ 168 The GraphicsPrimitive to display complex functions in using the domain 169 coloring method 170 171 INPUT: 172 173 - ``rgb_data`` -- An array of colored points to be plotted. 174 175 - ``xrange`` -- A minimum and maximum x value for the plot. 176 177 - ``yrange`` -- A minimum and maximum y value for the plot. 178 179 TESTS:: 180 181 sage: p = complex_plot(lambda z: z^2-1, (-2, 2), (-2, 2)) 182 """ 183 def __init__(self, rgb_data, xrange, yrange, options): 168 184 """ 169 185 TESTS:: 170 186 … … 172 172 """ 173 173 self.xrange = xrange 174 174 self.yrange = yrange 175 self.z_values = z_values176 self.x_count = len( z_values)177 self.y_count = len( z_values[0])178 self.rgb_data = complex_to_rgb(z_values)175 #self.z_values = z_values 176 self.x_count = len(rgb_data) 177 self.y_count = len(rgb_data[0]) 178 self.rgb_data = rgb_data 179 179 GraphicPrimitive.__init__(self, options) 180 180 181 181 def get_minmax_data(self): … … 333 333 sig_off() 334 334 g = Graphics() 335 335 g._set_extra_kwds(Graphics._extract_kwds_for_show(options, ignore=['xmin', 'xmax'])) 336 g.add_primitive(ComplexPlot( z_values, xrange, yrange, options))336 g.add_primitive(ComplexPlot(complex_to_rgb(z_values), xrange, yrange, options)) 337 337 return g