In [1]:
import random
import pandas as pd
from plotly.graph_objs import *
Using plotly offline mode
In [2]:
from plotly.offline import init_notebook_mode, iplot, plot
init_notebook_mode(connected=True)
Reading the final dataset
In [4]:
dataset = pd.read_csv('finalDataset.csv')
dataset.head(3)
Out[4]:
List of Seasons [Spring, Summer, Fall(Autum), Winter] with corresponding months
In [5]:
monthList = ['Mar|Apr|May', 'Jun|Jul|Aug', 'Sep|Oct|Nov', 'Dec|Jan|Feb']
List with
In [6]:
finalList = [['Spring', 'Summer', 'Fall(Autumn)', 'Winter'] ,\
[int(dataset[dataset.RELEASED.str.contains(seasonMonths, na = False)]['ADJ. BOX OFFICE'].mean()) \
for seasonMonths in monthList] , \
[len(dataset[dataset.RELEASED.str.contains(seasonMonths, na = False)]) \
for seasonMonths in monthList] , \
[round(dataset[dataset.RELEASED.str.contains(seasonMonths, na = False)]['RATING'].mean(), 2) \
for seasonMonths in monthList]]
Function that return dicitonary data to plot the data point
In [7]:
def data_(boxoffice, rating, movieCount, name):
return {
'x' : [boxoffice],
'y' : [rating],
'name' : name,
'mode' : 'markers',
'text' : 'Season: ' + name + \
'<br>Mean Rating: ' + str(rating) + \
'<br>Movie Count: ' + str(movieCount) + \
'<br>Mean BoxOffice: ' + str(round(boxoffice/1000000, 2)) + 'M',
'hoverinfo' : 'text',
'marker' : {
'size' : [movieCount],
'sizemode' : 'area',
'line' : {
'width' : 1
}
}
}
Adding Data to figure and setting x-axis, y-axis, title, background of layout
In [8]:
figure = {
'data': [data_(finalList[1][i], finalList[3][i], finalList[2][i], finalList[0][i]) for i in range(4)],
'layout' : {}
}
figure['layout']['xaxis'] = {'title' : 'Mean Box Office',
'titlefont': {
'size' : 16, 'family' : 'Droid Sans'
},
'showline' : True,
'ticks' : 'outside',
'tickwidth' : 2,
'gridcolor' : '#FFFFFF'}
figure['layout']['yaxis'] = {'title' : 'Mean Rating',
'titlefont' : {
'size' : 16 , 'family' : 'Droid Sans'
},
'showline' : True,
'ticks' : 'outside',
'tickwidth' : 2,
'gridcolor' : '#FFFFFF'}
figure['layout']['title'] = 'Season Movie Analysis'
figure['layout']['titlefont'] = {'size' : 20, 'family' : 'Times New Roman'}
figure['layout']['plot_bgcolor'] = 'rgb(223, 232, 243)'
In [9]:
# iplot(figure)
plot(figure)
Out[9]:
In [ ]: