Plotting data

Python intermedio per la finanza

Kennedy Behrman

Data Engineer, Author, Founder

Look at your data

Plot of stock prices

Python intermedio per la finanza
exxon.head()
Python intermedio per la finanza

Introducing the data

exxon.head()
    Date         High        Volume      Month
0   2015-05-01   90.089996   198924100   May
1   2015-06-01   85.970001   238808600   Jun
2   2015-07-01   83.529999   274029000   Jul
3   2015-08-01   79.290001   387523600   Aug
4   2015-09-01   75.470001   316644500   Sep

Python intermedio per la finanza

Matplotlib

my_dataframe.plot()
Python intermedio per la finanza

Line plot

exxon.plot(x='Date', 
           y='High' )
Python intermedio per la finanza

Line plot of stock prices

Python intermedio per la finanza

Rotate

exxon.plot(x='Date', 
           y='High', 
           rot=90 )
Python intermedio per la finanza

Line plot with rotated labels

Python intermedio per la finanza

Title

exxon.plot(x='Date', 
           y='High', 
           rot=90, 
           title='Exxon Stock Price')
Python intermedio per la finanza

Line plot with title

Python intermedio per la finanza

Index

exxon.set_index('Date', inplace=True)
exxon.plot(y='High', 
           rot=90, 
           title='Exxon Stock Price')
Python intermedio per la finanza

Line plot using index as x-axis

Python intermedio per la finanza

Plot types

  • line
  • bar
  • barh
  • hist
  • box
  • kde
  • density
  • area
  • pie
  • scatter
  • hexbin
Python intermedio per la finanza

Bar

exxon2018.plot(x='Month', 
               y='Volume', 
               kind='bar', 
               title='Exxon 2018')
Python intermedio per la finanza

Bar plot

Python intermedio per la finanza

Hist

exxon.plot(y='High',kind='hist')
Python intermedio per la finanza

Histogram

Python intermedio per la finanza

Let's practice!

Python intermedio per la finanza

Preparing Video For Download...