In [1]:
from numpy.random import *
from pylab import *
# import matplotlib.pyplot as plt
In [2]:
hist(randn(1000), 100)
Out[2]:
(array([  1.,   0.,   0.,   0.,   0.,   0.,   1.,   1.,   0.,   2.,   1.,
          1.,   1.,   0.,   2.,   4.,   1.,   4.,   6.,   5.,   7.,   6.,
          5.,   9.,  17.,   7.,   8.,  10.,  16.,  13.,  16.,  19.,  16.,
         23.,  17.,  26.,  21.,  18.,  25.,  19.,  34.,  12.,  13.,  25.,
         27.,  32.,  33.,  32.,  30.,  21.,  33.,  23.,  25.,  18.,  16.,
         24.,  28.,  15.,  24.,  14.,  16.,  13.,  24.,  13.,  21.,  10.,
         11.,  10.,   9.,   7.,   5.,   4.,   9.,   6.,   3.,   6.,   5.,
          4.,   1.,   4.,   2.,   2.,   0.,   0.,   0.,   2.,   1.,   0.,
          0.,   0.,   1.,   0.,   2.,   1.,   0.,   0.,   0.,   0.,   0.,
          1.]),
 array([-3.10180073, -3.03508963, -2.96837853, -2.90166744, -2.83495634,
        -2.76824524, -2.70153414, -2.63482304, -2.56811194, -2.50140084,
        -2.43468974, -2.36797865, -2.30126755, -2.23455645, -2.16784535,
        -2.10113425, -2.03442315, -1.96771205, -1.90100095, -1.83428985,
        -1.76757876, -1.70086766, -1.63415656, -1.56744546, -1.50073436,
        -1.43402326, -1.36731216, -1.30060106, -1.23388997, -1.16717887,
        -1.10046777, -1.03375667, -0.96704557, -0.90033447, -0.83362337,
        -0.76691227, -0.70020118, -0.63349008, -0.56677898, -0.50006788,
        -0.43335678, -0.36664568, -0.29993458, -0.23322348, -0.16651239,
        -0.09980129, -0.03309019,  0.03362091,  0.10033201,  0.16704311,
         0.23375421,  0.30046531,  0.36717641,  0.4338875 ,  0.5005986 ,
         0.5673097 ,  0.6340208 ,  0.7007319 ,  0.767443  ,  0.8341541 ,
         0.9008652 ,  0.96757629,  1.03428739,  1.10099849,  1.16770959,
         1.23442069,  1.30113179,  1.36784289,  1.43455399,  1.50126508,
         1.56797618,  1.63468728,  1.70139838,  1.76810948,  1.83482058,
         1.90153168,  1.96824278,  2.03495388,  2.10166497,  2.16837607,
         2.23508717,  2.30179827,  2.36850937,  2.43522047,  2.50193157,
         2.56864267,  2.63535376,  2.70206486,  2.76877596,  2.83548706,
         2.90219816,  2.96890926,  3.03562036,  3.10233146,  3.16904255,
         3.23575365,  3.30246475,  3.36917585,  3.43588695,  3.50259805,
         3.56930915]),
 <a list of 100 Patch objects>)
In [3]:
hist?
In [5]:
t = arange(0.0, 2.0, 0.01)
In [6]:
print t
[ 0.    0.01  0.02  0.03  0.04  0.05  0.06  0.07  0.08  0.09  0.1   0.11
  0.12  0.13  0.14  0.15  0.16  0.17  0.18  0.19  0.2   0.21  0.22  0.23
  0.24  0.25  0.26  0.27  0.28  0.29  0.3   0.31  0.32  0.33  0.34  0.35
  0.36  0.37  0.38  0.39  0.4   0.41  0.42  0.43  0.44  0.45  0.46  0.47
  0.48  0.49  0.5   0.51  0.52  0.53  0.54  0.55  0.56  0.57  0.58  0.59
  0.6   0.61  0.62  0.63  0.64  0.65  0.66  0.67  0.68  0.69  0.7   0.71
  0.72  0.73  0.74  0.75  0.76  0.77  0.78  0.79  0.8   0.81  0.82  0.83
  0.84  0.85  0.86  0.87  0.88  0.89  0.9   0.91  0.92  0.93  0.94  0.95
  0.96  0.97  0.98  0.99  1.    1.01  1.02  1.03  1.04  1.05  1.06  1.07
  1.08  1.09  1.1   1.11  1.12  1.13  1.14  1.15  1.16  1.17  1.18  1.19
  1.2   1.21  1.22  1.23  1.24  1.25  1.26  1.27  1.28  1.29  1.3   1.31
  1.32  1.33  1.34  1.35  1.36  1.37  1.38  1.39  1.4   1.41  1.42  1.43
  1.44  1.45  1.46  1.47  1.48  1.49  1.5   1.51  1.52  1.53  1.54  1.55
  1.56  1.57  1.58  1.59  1.6   1.61  1.62  1.63  1.64  1.65  1.66  1.67
  1.68  1.69  1.7   1.71  1.72  1.73  1.74  1.75  1.76  1.77  1.78  1.79
  1.8   1.81  1.82  1.83  1.84  1.85  1.86  1.87  1.88  1.89  1.9   1.91
  1.92  1.93  1.94  1.95  1.96  1.97  1.98  1.99]
In [7]:
s = sin(2*pi*t)
In [8]:
print s
[  0.00000000e+00   6.27905195e-02   1.25333234e-01   1.87381315e-01
   2.48689887e-01   3.09016994e-01   3.68124553e-01   4.25779292e-01
   4.81753674e-01   5.35826795e-01   5.87785252e-01   6.37423990e-01
   6.84547106e-01   7.28968627e-01   7.70513243e-01   8.09016994e-01
   8.44327926e-01   8.76306680e-01   9.04827052e-01   9.29776486e-01
   9.51056516e-01   9.68583161e-01   9.82287251e-01   9.92114701e-01
   9.98026728e-01   1.00000000e+00   9.98026728e-01   9.92114701e-01
   9.82287251e-01   9.68583161e-01   9.51056516e-01   9.29776486e-01
   9.04827052e-01   8.76306680e-01   8.44327926e-01   8.09016994e-01
   7.70513243e-01   7.28968627e-01   6.84547106e-01   6.37423990e-01
   5.87785252e-01   5.35826795e-01   4.81753674e-01   4.25779292e-01
   3.68124553e-01   3.09016994e-01   2.48689887e-01   1.87381315e-01
   1.25333234e-01   6.27905195e-02   1.22464680e-16  -6.27905195e-02
  -1.25333234e-01  -1.87381315e-01  -2.48689887e-01  -3.09016994e-01
  -3.68124553e-01  -4.25779292e-01  -4.81753674e-01  -5.35826795e-01
  -5.87785252e-01  -6.37423990e-01  -6.84547106e-01  -7.28968627e-01
  -7.70513243e-01  -8.09016994e-01  -8.44327926e-01  -8.76306680e-01
  -9.04827052e-01  -9.29776486e-01  -9.51056516e-01  -9.68583161e-01
  -9.82287251e-01  -9.92114701e-01  -9.98026728e-01  -1.00000000e+00
  -9.98026728e-01  -9.92114701e-01  -9.82287251e-01  -9.68583161e-01
  -9.51056516e-01  -9.29776486e-01  -9.04827052e-01  -8.76306680e-01
  -8.44327926e-01  -8.09016994e-01  -7.70513243e-01  -7.28968627e-01
  -6.84547106e-01  -6.37423990e-01  -5.87785252e-01  -5.35826795e-01
  -4.81753674e-01  -4.25779292e-01  -3.68124553e-01  -3.09016994e-01
  -2.48689887e-01  -1.87381315e-01  -1.25333234e-01  -6.27905195e-02
  -2.44929360e-16   6.27905195e-02   1.25333234e-01   1.87381315e-01
   2.48689887e-01   3.09016994e-01   3.68124553e-01   4.25779292e-01
   4.81753674e-01   5.35826795e-01   5.87785252e-01   6.37423990e-01
   6.84547106e-01   7.28968627e-01   7.70513243e-01   8.09016994e-01
   8.44327926e-01   8.76306680e-01   9.04827052e-01   9.29776486e-01
   9.51056516e-01   9.68583161e-01   9.82287251e-01   9.92114701e-01
   9.98026728e-01   1.00000000e+00   9.98026728e-01   9.92114701e-01
   9.82287251e-01   9.68583161e-01   9.51056516e-01   9.29776486e-01
   9.04827052e-01   8.76306680e-01   8.44327926e-01   8.09016994e-01
   7.70513243e-01   7.28968627e-01   6.84547106e-01   6.37423990e-01
   5.87785252e-01   5.35826795e-01   4.81753674e-01   4.25779292e-01
   3.68124553e-01   3.09016994e-01   2.48689887e-01   1.87381315e-01
   1.25333234e-01   6.27905195e-02   3.67394040e-16  -6.27905195e-02
  -1.25333234e-01  -1.87381315e-01  -2.48689887e-01  -3.09016994e-01
  -3.68124553e-01  -4.25779292e-01  -4.81753674e-01  -5.35826795e-01
  -5.87785252e-01  -6.37423990e-01  -6.84547106e-01  -7.28968627e-01
  -7.70513243e-01  -8.09016994e-01  -8.44327926e-01  -8.76306680e-01
  -9.04827052e-01  -9.29776486e-01  -9.51056516e-01  -9.68583161e-01
  -9.82287251e-01  -9.92114701e-01  -9.98026728e-01  -1.00000000e+00
  -9.98026728e-01  -9.92114701e-01  -9.82287251e-01  -9.68583161e-01
  -9.51056516e-01  -9.29776486e-01  -9.04827052e-01  -8.76306680e-01
  -8.44327926e-01  -8.09016994e-01  -7.70513243e-01  -7.28968627e-01
  -6.84547106e-01  -6.37423990e-01  -5.87785252e-01  -5.35826795e-01
  -4.81753674e-01  -4.25779292e-01  -3.68124553e-01  -3.09016994e-01
  -2.48689887e-01  -1.87381315e-01  -1.25333234e-01  -6.27905195e-02]
In [11]:
xlabel('time (s)')
ylabel('mV')
title('Oscilloscope')
ylim(-1.1, 1.1)
grid(True)
plot(t,s)
Out[11]:
[<matplotlib.lines.Line2D at 0x2ad28acb1790>]
In [10]:
rcParams['figure.figsize'] = 16,8 

In [12]:
from mpl_toolkits.basemap import Basemap
m = Basemap(projection='robin', lon_0=0,resolution='l')
m.drawcoastlines()
m.fillcontinents(color='brown', lake_color='aqua')
m.drawparallels(np.arange(-90.,90.,30.))
m.drawmeridians(np.arange(0.,360.,60.))
m.drawmapboundary()
plt.title("Robinson")
Out[12]:
<matplotlib.text.Text at 0x2ad2bb8c7950>
In [13]:
m = Basemap(projection='ortho', lon_0=-105,lat_0=40, resolution='l')

m.drawcoastlines()
m.fillcontinents(color='brown', lake_color='aqua')
m.drawparallels(np.arange(-90.,90.,30.))
m.drawmeridians(np.arange(0.,360.,60.))
m.drawmapboundary(fill_color='aqua')
plt.title("Tissot test")
ax = plt.gca()
for y in np.linspace(m.ymax/20, 19*m.ymax/20,10):
    for x in np.linspace(m.xmax/20, 19*m.xmax/20,10):
        lon, lat = m(x,y,inverse=True)
        poly = m.tissot(lon,lat,3,100)
In [16]:
for i in range(4):
    plot(randn(200).cumsum(), 
              label="test #" + str(i))
legend(loc="lower left")
Out[16]:
<matplotlib.legend.Legend at 0x2ad2ba2df610>
In [15]:
legend?
In [17]:
from numpy import linspace, sin
x = linspace(0, 10, 50)
xerr = random(len(x))*0.4
y = sin(x)
plot(x, y)
errorbar(x, y, xerr)
Out[17]:
<Container object of 3 artists>