@@ -210,28 +210,27 @@ def test_light_source_shading_color_range():
210210 #http://matplotlib.org/examples/pylab_examples/shading_example.html
211211
212212 from matplotlib .colors import LightSource
213+ from matplotlib .colors import Normalize
213214
214- norm = mcolors .Normalize (vmin = 0 , vmax = 50 )
215- # test data
216- X , Y = np .mgrid [- 5 :5 :0.05 , - 5 :5 :0.05 ]
217- Z = np .sqrt (X ** 2 + Y ** 2 ) + np .sin (X ** 2 + Y ** 2 )
218- # create light source object.
215+ refinput = np .array ([[1 , 2 , 3 , 4 ], [5 , 6 , 7 , 8 ], [9 , 10 , 11 , 12 ]])
216+ norm = Normalize (vmin = 0 , vmax = 50 )
219217 ls = LightSource (azdeg = 0 , altdeg = 65 )
220- # shade data, creating an rgb array.
221- rgb = ls .shade (Z , plt .cm .jet , norm = norm )
222- # plot un-shaded and shaded images.
223- plt .figure (figsize = (12 , 5 ))
224- plt .subplot (121 )
225- plt .imshow (Z , cmap = plt .cm .jet , norm = norm )
226- plt .title ('imshow' )
227- plt .xticks ([])
228- plt .yticks ([])
229- plt .subplot (122 )
230- plt .imshow (rgb )
231- plt .title ('imshow with shading' )
232- plt .xticks ([])
233- plt .yticks ([])
234- plt .draw ()
218+ testoutput = ls .shade (refinput , plt .cm .jet , norm = norm )
219+ refoutput = np .array ([
220+ [[0. , 0. , 0.58912656 , 1. ],
221+ [0. , 0. , 0.67825312 , 1. ],
222+ [0. , 0. , 0.76737968 , 1. ],
223+ [0. , 0. , 0.85650624 , 1. ]],
224+ [[0. , 0. , 0.9456328 , 1. ],
225+ [0. , 0. , 1. , 1. ],
226+ [0. , 0.04901961 , 1. , 1. ],
227+ [0. , 0.12745098 , 1. , 1. ]],
228+ [[0. , 0.22156863 , 1. , 1. ],
229+ [0. , 0.3 , 1. , 1. ],
230+ [0. , 0.37843137 , 1. , 1. ],
231+ [0. , 0.45686275 , 1. , 1. ]]
232+ ])
233+ assert_array_almost_equal (refoutput , testoutput )
235234
236235
237236if __name__ == '__main__' :
0 commit comments