In [20]:
% matplotlib inline
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
In [21]:
x = np.linspace(0, 10, 512) # evenly spaced grid
In [22]:
x
Out[22]:
array([  0.        ,   0.01956947,   0.03913894,   0.05870841,
         0.07827789,   0.09784736,   0.11741683,   0.1369863 ,
         0.15655577,   0.17612524,   0.19569472,   0.21526419,
         0.23483366,   0.25440313,   0.2739726 ,   0.29354207,
         0.31311155,   0.33268102,   0.35225049,   0.37181996,
         0.39138943,   0.4109589 ,   0.43052838,   0.45009785,
         0.46966732,   0.48923679,   0.50880626,   0.52837573,
         0.54794521,   0.56751468,   0.58708415,   0.60665362,
         0.62622309,   0.64579256,   0.66536204,   0.68493151,
         0.70450098,   0.72407045,   0.74363992,   0.76320939,
         0.78277886,   0.80234834,   0.82191781,   0.84148728,
         0.86105675,   0.88062622,   0.90019569,   0.91976517,
         0.93933464,   0.95890411,   0.97847358,   0.99804305,
         1.01761252,   1.037182  ,   1.05675147,   1.07632094,
         1.09589041,   1.11545988,   1.13502935,   1.15459883,
         1.1741683 ,   1.19373777,   1.21330724,   1.23287671,
         1.25244618,   1.27201566,   1.29158513,   1.3111546 ,
         1.33072407,   1.35029354,   1.36986301,   1.38943249,
         1.40900196,   1.42857143,   1.4481409 ,   1.46771037,
         1.48727984,   1.50684932,   1.52641879,   1.54598826,
         1.56555773,   1.5851272 ,   1.60469667,   1.62426614,
         1.64383562,   1.66340509,   1.68297456,   1.70254403,
         1.7221135 ,   1.74168297,   1.76125245,   1.78082192,
         1.80039139,   1.81996086,   1.83953033,   1.8590998 ,
         1.87866928,   1.89823875,   1.91780822,   1.93737769,
         1.95694716,   1.97651663,   1.99608611,   2.01565558,
         2.03522505,   2.05479452,   2.07436399,   2.09393346,
         2.11350294,   2.13307241,   2.15264188,   2.17221135,
         2.19178082,   2.21135029,   2.23091977,   2.25048924,
         2.27005871,   2.28962818,   2.30919765,   2.32876712,
         2.34833659,   2.36790607,   2.38747554,   2.40704501,
         2.42661448,   2.44618395,   2.46575342,   2.4853229 ,
         2.50489237,   2.52446184,   2.54403131,   2.56360078,
         2.58317025,   2.60273973,   2.6223092 ,   2.64187867,
         2.66144814,   2.68101761,   2.70058708,   2.72015656,
         2.73972603,   2.7592955 ,   2.77886497,   2.79843444,
         2.81800391,   2.83757339,   2.85714286,   2.87671233,
         2.8962818 ,   2.91585127,   2.93542074,   2.95499022,
         2.97455969,   2.99412916,   3.01369863,   3.0332681 ,
         3.05283757,   3.07240705,   3.09197652,   3.11154599,
         3.13111546,   3.15068493,   3.1702544 ,   3.18982387,
         3.20939335,   3.22896282,   3.24853229,   3.26810176,
         3.28767123,   3.3072407 ,   3.32681018,   3.34637965,
         3.36594912,   3.38551859,   3.40508806,   3.42465753,
         3.44422701,   3.46379648,   3.48336595,   3.50293542,
         3.52250489,   3.54207436,   3.56164384,   3.58121331,
         3.60078278,   3.62035225,   3.63992172,   3.65949119,
         3.67906067,   3.69863014,   3.71819961,   3.73776908,
         3.75733855,   3.77690802,   3.7964775 ,   3.81604697,
         3.83561644,   3.85518591,   3.87475538,   3.89432485,
         3.91389432,   3.9334638 ,   3.95303327,   3.97260274,
         3.99217221,   4.01174168,   4.03131115,   4.05088063,
         4.0704501 ,   4.09001957,   4.10958904,   4.12915851,
         4.14872798,   4.16829746,   4.18786693,   4.2074364 ,
         4.22700587,   4.24657534,   4.26614481,   4.28571429,
         4.30528376,   4.32485323,   4.3444227 ,   4.36399217,
         4.38356164,   4.40313112,   4.42270059,   4.44227006,
         4.46183953,   4.481409  ,   4.50097847,   4.52054795,
         4.54011742,   4.55968689,   4.57925636,   4.59882583,
         4.6183953 ,   4.63796477,   4.65753425,   4.67710372,
         4.69667319,   4.71624266,   4.73581213,   4.7553816 ,
         4.77495108,   4.79452055,   4.81409002,   4.83365949,
         4.85322896,   4.87279843,   4.89236791,   4.91193738,
         4.93150685,   4.95107632,   4.97064579,   4.99021526,
         5.00978474,   5.02935421,   5.04892368,   5.06849315,
         5.08806262,   5.10763209,   5.12720157,   5.14677104,
         5.16634051,   5.18590998,   5.20547945,   5.22504892,
         5.2446184 ,   5.26418787,   5.28375734,   5.30332681,
         5.32289628,   5.34246575,   5.36203523,   5.3816047 ,
         5.40117417,   5.42074364,   5.44031311,   5.45988258,
         5.47945205,   5.49902153,   5.518591  ,   5.53816047,
         5.55772994,   5.57729941,   5.59686888,   5.61643836,
         5.63600783,   5.6555773 ,   5.67514677,   5.69471624,
         5.71428571,   5.73385519,   5.75342466,   5.77299413,
         5.7925636 ,   5.81213307,   5.83170254,   5.85127202,
         5.87084149,   5.89041096,   5.90998043,   5.9295499 ,
         5.94911937,   5.96868885,   5.98825832,   6.00782779,
         6.02739726,   6.04696673,   6.0665362 ,   6.08610568,
         6.10567515,   6.12524462,   6.14481409,   6.16438356,
         6.18395303,   6.2035225 ,   6.22309198,   6.24266145,
         6.26223092,   6.28180039,   6.30136986,   6.32093933,
         6.34050881,   6.36007828,   6.37964775,   6.39921722,
         6.41878669,   6.43835616,   6.45792564,   6.47749511,
         6.49706458,   6.51663405,   6.53620352,   6.55577299,
         6.57534247,   6.59491194,   6.61448141,   6.63405088,
         6.65362035,   6.67318982,   6.6927593 ,   6.71232877,
         6.73189824,   6.75146771,   6.77103718,   6.79060665,
         6.81017613,   6.8297456 ,   6.84931507,   6.86888454,
         6.88845401,   6.90802348,   6.92759295,   6.94716243,
         6.9667319 ,   6.98630137,   7.00587084,   7.02544031,
         7.04500978,   7.06457926,   7.08414873,   7.1037182 ,
         7.12328767,   7.14285714,   7.16242661,   7.18199609,
         7.20156556,   7.22113503,   7.2407045 ,   7.26027397,
         7.27984344,   7.29941292,   7.31898239,   7.33855186,
         7.35812133,   7.3776908 ,   7.39726027,   7.41682975,
         7.43639922,   7.45596869,   7.47553816,   7.49510763,
         7.5146771 ,   7.53424658,   7.55381605,   7.57338552,
         7.59295499,   7.61252446,   7.63209393,   7.65166341,
         7.67123288,   7.69080235,   7.71037182,   7.72994129,
         7.74951076,   7.76908023,   7.78864971,   7.80821918,
         7.82778865,   7.84735812,   7.86692759,   7.88649706,
         7.90606654,   7.92563601,   7.94520548,   7.96477495,
         7.98434442,   8.00391389,   8.02348337,   8.04305284,
         8.06262231,   8.08219178,   8.10176125,   8.12133072,
         8.1409002 ,   8.16046967,   8.18003914,   8.19960861,
         8.21917808,   8.23874755,   8.25831703,   8.2778865 ,
         8.29745597,   8.31702544,   8.33659491,   8.35616438,
         8.37573386,   8.39530333,   8.4148728 ,   8.43444227,
         8.45401174,   8.47358121,   8.49315068,   8.51272016,
         8.53228963,   8.5518591 ,   8.57142857,   8.59099804,
         8.61056751,   8.63013699,   8.64970646,   8.66927593,
         8.6888454 ,   8.70841487,   8.72798434,   8.74755382,
         8.76712329,   8.78669276,   8.80626223,   8.8258317 ,
         8.84540117,   8.86497065,   8.88454012,   8.90410959,
         8.92367906,   8.94324853,   8.962818  ,   8.98238748,
         9.00195695,   9.02152642,   9.04109589,   9.06066536,
         9.08023483,   9.09980431,   9.11937378,   9.13894325,
         9.15851272,   9.17808219,   9.19765166,   9.21722114,
         9.23679061,   9.25636008,   9.27592955,   9.29549902,
         9.31506849,   9.33463796,   9.35420744,   9.37377691,
         9.39334638,   9.41291585,   9.43248532,   9.45205479,
         9.47162427,   9.49119374,   9.51076321,   9.53033268,
         9.54990215,   9.56947162,   9.5890411 ,   9.60861057,
         9.62818004,   9.64774951,   9.66731898,   9.68688845,
         9.70645793,   9.7260274 ,   9.74559687,   9.76516634,
         9.78473581,   9.80430528,   9.82387476,   9.84344423,
         9.8630137 ,   9.88258317,   9.90215264,   9.92172211,
         9.94129159,   9.96086106,   9.98043053,  10.        ])
In [23]:
(xx, yy) = np.meshgrid(x, x)
In [24]:
xx
Out[24]:
array([[  0.        ,   0.01956947,   0.03913894, ...,   9.96086106,
          9.98043053,  10.        ],
       [  0.        ,   0.01956947,   0.03913894, ...,   9.96086106,
          9.98043053,  10.        ],
       [  0.        ,   0.01956947,   0.03913894, ...,   9.96086106,
          9.98043053,  10.        ],
       ..., 
       [  0.        ,   0.01956947,   0.03913894, ...,   9.96086106,
          9.98043053,  10.        ],
       [  0.        ,   0.01956947,   0.03913894, ...,   9.96086106,
          9.98043053,  10.        ],
       [  0.        ,   0.01956947,   0.03913894, ...,   9.96086106,
          9.98043053,  10.        ]])
In [25]:
xx[0]
Out[25]:
array([  0.        ,   0.01956947,   0.03913894,   0.05870841,
         0.07827789,   0.09784736,   0.11741683,   0.1369863 ,
         0.15655577,   0.17612524,   0.19569472,   0.21526419,
         0.23483366,   0.25440313,   0.2739726 ,   0.29354207,
         0.31311155,   0.33268102,   0.35225049,   0.37181996,
         0.39138943,   0.4109589 ,   0.43052838,   0.45009785,
         0.46966732,   0.48923679,   0.50880626,   0.52837573,
         0.54794521,   0.56751468,   0.58708415,   0.60665362,
         0.62622309,   0.64579256,   0.66536204,   0.68493151,
         0.70450098,   0.72407045,   0.74363992,   0.76320939,
         0.78277886,   0.80234834,   0.82191781,   0.84148728,
         0.86105675,   0.88062622,   0.90019569,   0.91976517,
         0.93933464,   0.95890411,   0.97847358,   0.99804305,
         1.01761252,   1.037182  ,   1.05675147,   1.07632094,
         1.09589041,   1.11545988,   1.13502935,   1.15459883,
         1.1741683 ,   1.19373777,   1.21330724,   1.23287671,
         1.25244618,   1.27201566,   1.29158513,   1.3111546 ,
         1.33072407,   1.35029354,   1.36986301,   1.38943249,
         1.40900196,   1.42857143,   1.4481409 ,   1.46771037,
         1.48727984,   1.50684932,   1.52641879,   1.54598826,
         1.56555773,   1.5851272 ,   1.60469667,   1.62426614,
         1.64383562,   1.66340509,   1.68297456,   1.70254403,
         1.7221135 ,   1.74168297,   1.76125245,   1.78082192,
         1.80039139,   1.81996086,   1.83953033,   1.8590998 ,
         1.87866928,   1.89823875,   1.91780822,   1.93737769,
         1.95694716,   1.97651663,   1.99608611,   2.01565558,
         2.03522505,   2.05479452,   2.07436399,   2.09393346,
         2.11350294,   2.13307241,   2.15264188,   2.17221135,
         2.19178082,   2.21135029,   2.23091977,   2.25048924,
         2.27005871,   2.28962818,   2.30919765,   2.32876712,
         2.34833659,   2.36790607,   2.38747554,   2.40704501,
         2.42661448,   2.44618395,   2.46575342,   2.4853229 ,
         2.50489237,   2.52446184,   2.54403131,   2.56360078,
         2.58317025,   2.60273973,   2.6223092 ,   2.64187867,
         2.66144814,   2.68101761,   2.70058708,   2.72015656,
         2.73972603,   2.7592955 ,   2.77886497,   2.79843444,
         2.81800391,   2.83757339,   2.85714286,   2.87671233,
         2.8962818 ,   2.91585127,   2.93542074,   2.95499022,
         2.97455969,   2.99412916,   3.01369863,   3.0332681 ,
         3.05283757,   3.07240705,   3.09197652,   3.11154599,
         3.13111546,   3.15068493,   3.1702544 ,   3.18982387,
         3.20939335,   3.22896282,   3.24853229,   3.26810176,
         3.28767123,   3.3072407 ,   3.32681018,   3.34637965,
         3.36594912,   3.38551859,   3.40508806,   3.42465753,
         3.44422701,   3.46379648,   3.48336595,   3.50293542,
         3.52250489,   3.54207436,   3.56164384,   3.58121331,
         3.60078278,   3.62035225,   3.63992172,   3.65949119,
         3.67906067,   3.69863014,   3.71819961,   3.73776908,
         3.75733855,   3.77690802,   3.7964775 ,   3.81604697,
         3.83561644,   3.85518591,   3.87475538,   3.89432485,
         3.91389432,   3.9334638 ,   3.95303327,   3.97260274,
         3.99217221,   4.01174168,   4.03131115,   4.05088063,
         4.0704501 ,   4.09001957,   4.10958904,   4.12915851,
         4.14872798,   4.16829746,   4.18786693,   4.2074364 ,
         4.22700587,   4.24657534,   4.26614481,   4.28571429,
         4.30528376,   4.32485323,   4.3444227 ,   4.36399217,
         4.38356164,   4.40313112,   4.42270059,   4.44227006,
         4.46183953,   4.481409  ,   4.50097847,   4.52054795,
         4.54011742,   4.55968689,   4.57925636,   4.59882583,
         4.6183953 ,   4.63796477,   4.65753425,   4.67710372,
         4.69667319,   4.71624266,   4.73581213,   4.7553816 ,
         4.77495108,   4.79452055,   4.81409002,   4.83365949,
         4.85322896,   4.87279843,   4.89236791,   4.91193738,
         4.93150685,   4.95107632,   4.97064579,   4.99021526,
         5.00978474,   5.02935421,   5.04892368,   5.06849315,
         5.08806262,   5.10763209,   5.12720157,   5.14677104,
         5.16634051,   5.18590998,   5.20547945,   5.22504892,
         5.2446184 ,   5.26418787,   5.28375734,   5.30332681,
         5.32289628,   5.34246575,   5.36203523,   5.3816047 ,
         5.40117417,   5.42074364,   5.44031311,   5.45988258,
         5.47945205,   5.49902153,   5.518591  ,   5.53816047,
         5.55772994,   5.57729941,   5.59686888,   5.61643836,
         5.63600783,   5.6555773 ,   5.67514677,   5.69471624,
         5.71428571,   5.73385519,   5.75342466,   5.77299413,
         5.7925636 ,   5.81213307,   5.83170254,   5.85127202,
         5.87084149,   5.89041096,   5.90998043,   5.9295499 ,
         5.94911937,   5.96868885,   5.98825832,   6.00782779,
         6.02739726,   6.04696673,   6.0665362 ,   6.08610568,
         6.10567515,   6.12524462,   6.14481409,   6.16438356,
         6.18395303,   6.2035225 ,   6.22309198,   6.24266145,
         6.26223092,   6.28180039,   6.30136986,   6.32093933,
         6.34050881,   6.36007828,   6.37964775,   6.39921722,
         6.41878669,   6.43835616,   6.45792564,   6.47749511,
         6.49706458,   6.51663405,   6.53620352,   6.55577299,
         6.57534247,   6.59491194,   6.61448141,   6.63405088,
         6.65362035,   6.67318982,   6.6927593 ,   6.71232877,
         6.73189824,   6.75146771,   6.77103718,   6.79060665,
         6.81017613,   6.8297456 ,   6.84931507,   6.86888454,
         6.88845401,   6.90802348,   6.92759295,   6.94716243,
         6.9667319 ,   6.98630137,   7.00587084,   7.02544031,
         7.04500978,   7.06457926,   7.08414873,   7.1037182 ,
         7.12328767,   7.14285714,   7.16242661,   7.18199609,
         7.20156556,   7.22113503,   7.2407045 ,   7.26027397,
         7.27984344,   7.29941292,   7.31898239,   7.33855186,
         7.35812133,   7.3776908 ,   7.39726027,   7.41682975,
         7.43639922,   7.45596869,   7.47553816,   7.49510763,
         7.5146771 ,   7.53424658,   7.55381605,   7.57338552,
         7.59295499,   7.61252446,   7.63209393,   7.65166341,
         7.67123288,   7.69080235,   7.71037182,   7.72994129,
         7.74951076,   7.76908023,   7.78864971,   7.80821918,
         7.82778865,   7.84735812,   7.86692759,   7.88649706,
         7.90606654,   7.92563601,   7.94520548,   7.96477495,
         7.98434442,   8.00391389,   8.02348337,   8.04305284,
         8.06262231,   8.08219178,   8.10176125,   8.12133072,
         8.1409002 ,   8.16046967,   8.18003914,   8.19960861,
         8.21917808,   8.23874755,   8.25831703,   8.2778865 ,
         8.29745597,   8.31702544,   8.33659491,   8.35616438,
         8.37573386,   8.39530333,   8.4148728 ,   8.43444227,
         8.45401174,   8.47358121,   8.49315068,   8.51272016,
         8.53228963,   8.5518591 ,   8.57142857,   8.59099804,
         8.61056751,   8.63013699,   8.64970646,   8.66927593,
         8.6888454 ,   8.70841487,   8.72798434,   8.74755382,
         8.76712329,   8.78669276,   8.80626223,   8.8258317 ,
         8.84540117,   8.86497065,   8.88454012,   8.90410959,
         8.92367906,   8.94324853,   8.962818  ,   8.98238748,
         9.00195695,   9.02152642,   9.04109589,   9.06066536,
         9.08023483,   9.09980431,   9.11937378,   9.13894325,
         9.15851272,   9.17808219,   9.19765166,   9.21722114,
         9.23679061,   9.25636008,   9.27592955,   9.29549902,
         9.31506849,   9.33463796,   9.35420744,   9.37377691,
         9.39334638,   9.41291585,   9.43248532,   9.45205479,
         9.47162427,   9.49119374,   9.51076321,   9.53033268,
         9.54990215,   9.56947162,   9.5890411 ,   9.60861057,
         9.62818004,   9.64774951,   9.66731898,   9.68688845,
         9.70645793,   9.7260274 ,   9.74559687,   9.76516634,
         9.78473581,   9.80430528,   9.82387476,   9.84344423,
         9.8630137 ,   9.88258317,   9.90215264,   9.92172211,
         9.94129159,   9.96086106,   9.98043053,  10.        ])
In [26]:
xx[0:5, 0:5]
Out[26]:
array([[ 0.        ,  0.01956947,  0.03913894,  0.05870841,  0.07827789],
       [ 0.        ,  0.01956947,  0.03913894,  0.05870841,  0.07827789],
       [ 0.        ,  0.01956947,  0.03913894,  0.05870841,  0.07827789],
       [ 0.        ,  0.01956947,  0.03913894,  0.05870841,  0.07827789],
       [ 0.        ,  0.01956947,  0.03913894,  0.05870841,  0.07827789]])
In [27]:
yy[0:5, 0:5]
Out[27]:
array([[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ],
       [ 0.01956947,  0.01956947,  0.01956947,  0.01956947,  0.01956947],
       [ 0.03913894,  0.03913894,  0.03913894,  0.03913894,  0.03913894],
       [ 0.05870841,  0.05870841,  0.05870841,  0.05870841,  0.05870841],
       [ 0.07827789,  0.07827789,  0.07827789,  0.07827789,  0.07827789]])
In [33]:
zz = np.exp( (-(xx-5)**2 - (yy-5)**2)/(10) )
In [34]:
zz[0:5, 0:5]
Out[34]:
array([[ 0.00673795,  0.00687084,  0.00700582,  0.0071429 ,  0.00728211],
       [ 0.00687084,  0.00700636,  0.007144  ,  0.00728378,  0.00742573],
       [ 0.00700582,  0.007144  ,  0.00728434,  0.00742687,  0.00757161],
       [ 0.0071429 ,  0.00728378,  0.00742687,  0.00757219,  0.00771977],
       [ 0.00728211,  0.00742573,  0.00757161,  0.00771977,  0.00787022]])
In [35]:
plt.imshow(zz)
Out[35]:
<matplotlib.image.AxesImage at 0x11832f320>
In [36]:
plt.figure()
axis = plt.subplot(111, projection='3d')
axis.plot_surface(xx, yy, zz)
Out[36]:
<mpl_toolkits.mplot3d.art3d.Poly3DCollection at 0x118cca780>
In [ ]: