matplotlib


In [1]:
mean_temp = [ 0.        ,   0.4      ,   1.1,   1.7      ,
         2.4,   3.1      ,   3.8       ,   3.9,
         5.2,   5.5,   6.0      ,   5.9       ,
         8.3      ,   7.7,   8.3,   9.5       ,
         9.5,  10.6,  11.5,  12.3      ,
        13.2      ,  11.9,  11.03,  10.1,
        10.        ,   8.6,   9.1      ,   7.2      ,
         7.3,   6.5,   6.0,   5.9      ,
         5.1,   3.6       ,   3.3       ,   3.5,
         2.4,   1.5       ,   1.1,   0.5]
max_temp = [ 18.,  18.,  19.,  17.,  17.,  18.,  17.,  20.,  17.,  18.,  18.,
        18.,  17.,  16.,  17.,  18.,  19.,  19.,  17.,  19.,  19.,  16.,
        17.,  15.,  17.,  17.,  18.,  17.,  20.,  17.,  16.,  19.,  15.,
        15.,  19.,  17.,  16.,  17.,  19.,  16.,  18.,  19.,  16.,  19.,
        18.,  16.,  19.,  15.,  16.,  18.,  14.,  20.,  17.,  15.,  17.,
        16.,  17.,  19.,  18.,  18.]

Exercises

  1. Select the first element of 'mean_temp'.
  2. Select the last element of 'max_temp'.
  3. Create a new vector containing the elements on positions 3, 4 and 5 from 'mean_temp' and the elements on positions 10, 11 and 12 from 'max_temp'.

In [ ]:
a = mean_temp[0]
N = len(max_temp)
b = max_temp[N-1]
# or
b = max_temp[-1]
vec = mean_temp[3:6]+max_temp[10:13]

In [ ]:
print(a, b, vec)

In [ ]:
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

In [ ]:
plt.plot(mean_temp)
plt.title('Mean of temperatures')
plt.xlabel('Days')
plt.ylabel('Temperature')

In [ ]:
def sawtooth(x):
    return int(x)%2

In [ ]:
x = np.linspace(0,20,20)
y = np.array([sawtooth(xk) for xk in x])
plt.plot(x,y)

In [ ]:
ind = range(len(mean_temp))
width = 1

plt.bar(ind, mean_temp, width)
plt.show()

In [ ]:
bins = 10
plt.hist(mean_temp,bins,color='g')
plt.show()

bokeh


In [2]:
from bokeh.io import output_notebook,show
output_notebook()
from bokeh.charts import Line


BokehJS successfully loaded.
/home/leonardo/Applications/anaconda/envs/py3k/lib/python3.3/site-packages/blaze/utils.py:23: DeprecationWarning: NUM_CPUS constant is deprecated; use cpu_count() instead
  thread_pool = ThreadPool(psutil.NUM_CPUS)

In [3]:
p = Line(mean_temp,
        title = 'Temperature means',
        xlabel = 'Days',
        ylabel = 'Temperatures', 
        palette = ['blue']
        )
show(p)



In [4]:
from bokeh.charts import Bar

p = Bar(mean_temp,
       [str(i) for i in range(len(mean_temp))],
        title = 'Temperature means'
       )

show(p)



In [7]:
from bokeh.charts import Histogram

p = Histogram(max_temp,
             bins = 4,
             density = False,
             palette = ['blue']
             )

show(p)


ERROR:/home/leonardo/Applications/anaconda/envs/py3k/lib/python3.3/site-packages/bokeh/validation/check.py:E-1000 (COLUMN_LENGTHS): ColumnDataSource column lengths are not all the same: ColumnDataSource, ViewModel:ColumnDataSource, ref _id: f208f504-3eb5-4906-ad48-1b9ae5058d19

In [ ]: