Profile picture

1.10 - Intro to Matplotlib

Last updated: February 16th, 20192019-02-16Project preview

rmotr


Intro to Matplotlib - Exercises

In [ ]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

%matplotlib inline

green-divider

Exercise 1

Read cinema-income-madrid.csv as a DataFrame and store it in a df variable.

value column values are expressed in million dollars

In [ ]:
# your code goes here
In [ ]:
df = pd.read_csv('data/cinema-income-madrid.csv',
                 parse_dates=[0])

df.head()

green-divider

Exercise 2

Define date column as index of df.

In [ ]:
# your code goes here
In [ ]:
df.set_index('date', inplace=True)

df.head()

green-divider

Exercise 3

Using matplotlib draw a simple line plot using the value column.

In [ ]:
# your code goes here

Remember that plt.plot() function needs as argument the coordinates of the points or line nodes:

  • x: indexes of our df variable
  • y: elements within value column
In [ ]:
plt.plot(df.index, df['value'])

green-divider

Exercise 4

Show the same previous plot using a bigger figure size.

In [ ]:
# your code goes here

Remember that to modify the size of the figure is necesary to use plt.figure() function with figsize argument.

In [ ]:
plt.figure(figsize=(12, 8))

plt.plot(df.index, df['value'])

green-divider

Exercise 5

Make a line plot showing just the first 24 elements of the data.

In [ ]:
# your code goes here
In [ ]:
plt.figure(figsize=(12, 8))

plt.plot(df.index[0:24], df['value'].iloc[0:24])

green-divider

Exercise 6

Using matplotlib draw a simple histogram of the elements within value column.

In [ ]:
# your code goes here

Remember that plt.hist() function is used to create histograms.

In [ ]:
plt.hist(df['value'])

purple-divider

Notebooks AI
Notebooks AI Profile20060