In [77]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import c
%matplotlib inline
In [5]:
from plotly.offline import download_plotlyjs, init_notebook_mode, plot
from plotly.graph_objs import *
init_notebook_mode()
file = "./Playdata.xlsx"
#df = pd.read_excel(file, sheetname = 'Sheet1', header = 0, index_col = 0, convert_float = True)
#dv = pd.read_excel(file, sheetname = 'Sheet3', header = 0, index_col = 0, convert_float = True)
df = pd.read_excel(file, sheetname = 'Sheet1', header = 0, convert_float = True)
dv = pd.read_excel(file, sheetname = 'Sheet3', header = 0, index_col = 0, convert_float = True)
df['protein_percent'] = df['protein']/dv['DV']['Protein'] *100
df['totalcal'] = df['calperserv']/dv['DV']['Caloriesm'] * 100
df['foodtext'] = "\nCalories : " + str(df['calperserv']) + "\nProtein : " + str(df['protein'])
In [8]:
foodgrp_key= list(set(df['foodgroup']))
grp_val = list(map(int,range(len(foodgrp_key))))
grpdict = dict(zip(foodgrp_key,grp_val))
#for i in df["foodgroup"]:
# df["grpnumbers"] = grphash[df["foodgroup"][i]]
In [11]:
grpdict
Out[11]:
In [37]:
grpdict["Burger"]
Out[37]:
In [67]:
converter = {}
i=1
for item in df["foodgroup"]:
if item not in converter:
converter[item] =i
i += 1
df['foodgrpnum'] = [converter[i] for i in df["foodgroup"]]
In [76]:
df['foodgrpnum']#df['foodgrpnum'] = df.apply(lambda row: [v for k, v in new_data.items() if row['foodgroup'] == k][0], axis = 1)
Out[76]:
In [73]:
plot({
'data': [
Scatter(x=df['calperserv'],
y=df['score'],
text=df['foodtext'],
#marker=Marker(size=df['calperserv'], sizemode='area'), #, sizeref=131868,),
marker = dict(size= 14,
line= dict(width=1),
color= c[i],
opacity= 0.3
),name= y[i],
mode='markers',
)
],
'layout': Layout(title='Nutrition and Calorie Count',xaxis=XAxis(title='Calories per Serving'), yaxis=YAxis(title='Nutrition 1-10'),
hovermode = closest)
}, show_link=False)
Out[73]:
In [57]:
type(df[['foodgrpnum']])
In [75]:
N=53
c= ['hsl('+str(h)+',50%'+',50%)' for h in np.linspace(0, 360, N)]
c
Out[75]:
In [79]:
cl.scales['3']['div']['RdYlBu']))
In [2]:
#Create a palette of 4 colors of hues from 0 to 360, saturations between
# 0.1 and 0.5, and lightness from 0.6 to 0.85
pal <- qualpal(n = 4, list(h = c(0, 360), s = c(0.1, 0.5), l = c(0.6, 0.85)))
# Look at the colors in hex format
pal$hex
#> [1] "#6F75CE" "#CC6B76" "#CAC16A" "#76D0D0"
# Create a palette using one of the predefined color subspaces
pal2 <- qualpal(n = 4, colorspace = "pretty")
# Distance matrix of the DIN99d color differences
pal2$de_DIN99d
#> #69A3CC #6ECC6E #CA6BC4
#> 6ECC6E 22
#> CA6BC4 21 30
#> CD976B 24 21 21
plot(pal2)
In [ ]: