Skip to content
#importing libraries
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

#pulling the df
burn_energy = pd.read_csv('Calorie_project.csv')
display(burn_energy)
# Plotting a line plot for the timeline series based on the heartbeats per minute
fig, ax=plt.subplots()
plt.title('Source of energy consumption as per the Heart Rate')
plt.style.use("seaborn-deep")

ax.plot(burn_energy['heart_rate'], burn_energy['fat_KCal/min'], color = 'r', marker = 'o', label = 'Fats')
ax.set(xlabel='Heart Rate - beats/minute', ylabel='Fats Burned Kilocalorie/minute')
ax.legend(loc=2)

ax2=ax.twinx()
ax2.plot(burn_energy['heart_rate'], burn_energy['carb_KCal/min'], color = 'g', marker='s', label = "Carbs")
ax2.set_ylabel('Carbs Burned Kilocalorie/minute')
ax2.legend(loc=4)

# Set y-limits to be the same for both y-axes
y1_min, y1_max = ax.get_ylim()
y2_min, y2_max = ax2.get_ylim()

common_min = min(y1_min, y2_min)
common_max = max(y1_max, y2_max)

ax.set_ylim(common_min, common_max)
ax2.set_ylim(common_min, common_max)


plt.show()
# Subsetting the main df
perc = burn_energy[['heart_rate', 'perc_from_fat', 'perc_from_carbs']]

# Plotting the stacked percentage bar plot
plt.style.use("seaborn-colorblind")
perc.plot(x='heart_rate', kind='barh', stacked=True, mark_right=True, title = '% Share of Energy Consumption - Fats Vs Carbs')
plt.figure(figsize=(6,10))
plt.show()