This is the "python for Data Analysis" lesson.

It uses jupyter ipython notebook.

In this first ipython class let's see

Teacher: Mickael

Tester: Christian

website: hu datascience


In [1]:
# ==  Basic import == #
# plot within the notebook
%matplotlib inline
# No annoying warnings
import warnings
warnings.filterwarnings('ignore')

Create the Data


Create two random variables, "x" and "y". Each must be an array of 100 points between 0 and 1 from an uniform distribution.

Starts by importing numpy and then, use the random class numpy has. (more information about numpy.random here)


In [ ]:

Print the variable to check the numbers looks correct.


In [ ]:

Visualize the Data


Histograms

Start by importing the pyplot library of matplotlib.pyplot (matplotlib.pyplot).

All you need to know about matplotlib is here. Make use of this website that have most of what you need to ba able to use this plotting library (check this for instance).

How the figures should look like?

In the figures make:

  • histograms of "x" and "y" on 2 different figures.
  • "x" yellow and "y" blue
  • "x" with 12 bins and "y" with only 8.

In [ ]:

Shared axis

show x and y histograms in the same figure, give them labels ("y" as "rain" and "x" as "sun") and show the legend.


In [ ]:

Make the plot pretty

Most likely you do not see things really well... So first, force thenm to share the same range (say between -0.2 and 1.2), with 7 bins. Then, change the style (type) of the histogram to step. (use the shift-tab -you can do it twice in a row- trip to see function options). The x and y must still be yellow and blue and we should still see the legend.

Alsom make the "sun" line thicker (say 2) and more transparent (say to 0.5).

Tip check the lw (linewidth), ec (edgecolor), alpha, etc. options


In [ ]:

Last fancy step.

the "rain" should be shown under the "sun" and it should be fully colored in blue (see the fill option). The x-axis should be labeled "chance to have rain/sun". and the y-axis, number of hours.

and make it as pertty as you wish.


In [ ]:

SCATTER PLOT

Show the two y as a function of x. The marker should not be linked together by a line. The marker should be blue and the edge black. The x-axis should be called "chance of sun" and the y-axis "chance to have rain"


In [ ]: