@@ -2364,3 +2364,82 @@ def test_is_polar_3d():
23642364 x22 , y22 = x1 * np .cos (y1 ), x1 * np .sin (y1 )
23652365 assert np .allclose (x2 , x22 )
23662366 assert np .allclose (y2 , y22 )
2367+
2368+
2369+ def test_color_func ():
2370+ # verify that eval_color_func produces the expected results in order to
2371+ # maintain back compatibility with the old sympy.plotting module
2372+
2373+ x , y , z , u , v = symbols ("x, y, z, u, v" )
2374+
2375+ s = LineOver1DRangeSeries (sin (x ), (x , - 5 , 5 ), adaptive = False , n = 10 ,
2376+ color_func = lambda x : x )
2377+ xx , yy , col = s .get_data ()
2378+ assert np .allclose (col , xx )
2379+ s = LineOver1DRangeSeries (sin (x ), (x , - 5 , 5 ), adaptive = False , n = 10 ,
2380+ color_func = lambda x , y : y )
2381+ xx , yy , col = s .get_data ()
2382+ assert np .allclose (col , yy )
2383+
2384+ s = Parametric2DLineSeries (cos (x ), sin (x ), (x , 0 , 2 * pi ),
2385+ adaptive = False , n = 10 , color_func = lambda t : t )
2386+ xx , yy , col = s .get_data ()
2387+ assert (not np .allclose (xx , col )) and (not np .allclose (yy , col ))
2388+ s = Parametric2DLineSeries (cos (x ), sin (x ), (x , 0 , 2 * pi ),
2389+ adaptive = False , n = 10 , color_func = lambda x , y : x * y )
2390+ xx , yy , col = s .get_data ()
2391+ assert np .allclose (col , xx * yy )
2392+ s = Parametric2DLineSeries (cos (x ), sin (x ), (x , 0 , 2 * pi ),
2393+ adaptive = False , n = 10 , color_func = lambda x , y , t : x * y * t )
2394+ xx , yy , col = s .get_data ()
2395+ assert np .allclose (col , xx * yy * np .linspace (0 , 2 * np .pi , 10 ))
2396+
2397+ s = Parametric3DLineSeries (cos (x ), sin (x ), x , (x , 0 , 2 * pi ),
2398+ adaptive = False , n = 10 , color_func = lambda t : t )
2399+ xx , yy , zz , col = s .get_data ()
2400+ assert (not np .allclose (xx , col )) and (not np .allclose (yy , col ))
2401+ s = Parametric3DLineSeries (cos (x ), sin (x ), x , (x , 0 , 2 * pi ),
2402+ adaptive = False , n = 10 , color_func = lambda x , y , z : x * y * z )
2403+ xx , yy , zz , col = s .get_data ()
2404+ assert np .allclose (col , xx * yy * zz )
2405+ s = Parametric3DLineSeries (cos (x ), sin (x ), x , (x , 0 , 2 * pi ),
2406+ adaptive = False , n = 10 , color_func = lambda x , y , z , t : x * y * z * t )
2407+ xx , yy , zz , col = s .get_data ()
2408+ assert np .allclose (col , xx * yy * zz * np .linspace (0 , 2 * np .pi , 10 ))
2409+
2410+ s = SurfaceOver2DRangeSeries (cos (x ** 2 + y ** 2 ), (x , - 2 , 2 ), (y , - 2 , 2 ),
2411+ adaptive = False , n1 = 10 , n2 = 10 , color_func = lambda x : x )
2412+ xx , yy , zz = s .get_data ()
2413+ col = s .eval_color_func (xx , yy , zz )
2414+ assert np .allclose (xx , col )
2415+ s = SurfaceOver2DRangeSeries (cos (x ** 2 + y ** 2 ), (x , - 2 , 2 ), (y , - 2 , 2 ),
2416+ adaptive = False , n1 = 10 , n2 = 10 , color_func = lambda x , y : x * y )
2417+ xx , yy , zz = s .get_data ()
2418+ col = s .eval_color_func (xx , yy , zz )
2419+ assert np .allclose (xx * yy , col )
2420+ s = SurfaceOver2DRangeSeries (cos (x ** 2 + y ** 2 ), (x , - 2 , 2 ), (y , - 2 , 2 ),
2421+ adaptive = False , n1 = 10 , n2 = 10 , color_func = lambda x , y , z : x * y * z )
2422+ xx , yy , zz = s .get_data ()
2423+ col = s .eval_color_func (xx , yy , zz )
2424+ assert np .allclose (xx * yy * zz , col )
2425+
2426+ s = ParametricSurfaceSeries (1 , x , y , (x , 0 , 1 ), (y , 0 , 1 ), adaptive = False ,
2427+ n1 = 10 , n2 = 10 , color_func = lambda u :u )
2428+ xx , yy , zz , uu , vv = s .get_data ()
2429+ col = s .eval_color_func (xx , yy , zz , uu , vv )
2430+ assert np .allclose (uu , col )
2431+ s = ParametricSurfaceSeries (1 , x , y , (x , 0 , 1 ), (y , 0 , 1 ), adaptive = False ,
2432+ n1 = 10 , n2 = 10 , color_func = lambda u , v : u * v )
2433+ xx , yy , zz , uu , vv = s .get_data ()
2434+ col = s .eval_color_func (xx , yy , zz , uu , vv )
2435+ assert np .allclose (uu * vv , col )
2436+ s = ParametricSurfaceSeries (1 , x , y , (x , 0 , 1 ), (y , 0 , 1 ), adaptive = False ,
2437+ n1 = 10 , n2 = 10 , color_func = lambda x , y , z : x * y * z )
2438+ xx , yy , zz , uu , vv = s .get_data ()
2439+ col = s .eval_color_func (xx , yy , zz , uu , vv )
2440+ assert np .allclose (xx * yy * zz , col )
2441+ s = ParametricSurfaceSeries (1 , x , y , (x , 0 , 1 ), (y , 0 , 1 ), adaptive = False ,
2442+ n1 = 10 , n2 = 10 , color_func = lambda x , y , z , u , v : x * y * z * u * v )
2443+ xx , yy , zz , uu , vv = s .get_data ()
2444+ col = s .eval_color_func (xx , yy , zz , uu , vv )
2445+ assert np .allclose (xx * yy * zz * uu * vv , col )
0 commit comments