├── .gitignore ├── requirements.txt ├── .vscode └── settings.json ├── examples ├── Figure_1.png └── Figure_2.png ├── .gitpod.yml ├── README.md ├── main.py ├── medical_data_visualizer.py └── test_module.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | seaborn==0.13.2 2 | pandas==1.5.3 3 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "workbench.colorTheme": "freeCodeCamp Dark Theme" 3 | } 4 | -------------------------------------------------------------------------------- /examples/Figure_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freeCodeCamp/boilerplate-medical-data-visualizer/HEAD/examples/Figure_1.png -------------------------------------------------------------------------------- /examples/Figure_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freeCodeCamp/boilerplate-medical-data-visualizer/HEAD/examples/Figure_2.png -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: gitpod/workspace-python-3.8 2 | 3 | tasks: 4 | - init: pip install -r requirements.txt 5 | 6 | vscode: 7 | extensions: 8 | - https://github.com/freeCodeCamp/freecodecamp-dark-vscode-theme/releases/download/v1.0.0/freecodecamp-dark-vscode-theme-1.0.0.vsix 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Medical Data Visualizer 2 | 3 | This is the boilerplate for the Medical Data Visualizer project. Instructions for building your project can be found at https://www.freecodecamp.org/learn/data-analysis-with-python/data-analysis-with-python-projects/medical-data-visualizer 4 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # This entrypoint file to be used in development. Start by reading README.md 2 | import medical_data_visualizer 3 | from unittest import main 4 | 5 | # Test your function by calling it here 6 | medical_data_visualizer.draw_cat_plot() 7 | medical_data_visualizer.draw_heat_map() 8 | 9 | # Run unit tests automatically 10 | main(module='test_module', exit=False) -------------------------------------------------------------------------------- /medical_data_visualizer.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import seaborn as sns 3 | import matplotlib.pyplot as plt 4 | import numpy as np 5 | 6 | # 1 7 | df = None 8 | 9 | # 2 10 | df['overweight'] = None 11 | 12 | # 3 13 | 14 | 15 | # 4 16 | def draw_cat_plot(): 17 | # 5 18 | df_cat = None 19 | 20 | 21 | # 6 22 | df_cat = None 23 | 24 | 25 | # 7 26 | 27 | 28 | 29 | # 8 30 | fig = None 31 | 32 | 33 | # 9 34 | fig.savefig('catplot.png') 35 | return fig 36 | 37 | 38 | # 10 39 | def draw_heat_map(): 40 | # 11 41 | df_heat = None 42 | 43 | # 12 44 | corr = None 45 | 46 | # 13 47 | mask = None 48 | 49 | 50 | 51 | # 14 52 | fig, ax = None 53 | 54 | # 15 55 | 56 | 57 | 58 | # 16 59 | fig.savefig('heatmap.png') 60 | return fig 61 | -------------------------------------------------------------------------------- /test_module.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import medical_data_visualizer 3 | import matplotlib as mpl 4 | 5 | 6 | # the test case 7 | class CatPlotTestCase(unittest.TestCase): 8 | def setUp(self): 9 | self.fig = medical_data_visualizer.draw_cat_plot() 10 | self.ax = self.fig.axes[0] 11 | 12 | def test_line_plot_labels(self): 13 | actual = self.ax.get_xlabel() 14 | expected = "variable" 15 | self.assertEqual(actual, expected, "Expected line plot xlabel to be 'variable'") 16 | actual = self.ax.get_ylabel() 17 | expected = "total" 18 | self.assertEqual(actual, expected, "Expected line plot ylabel to be 'total'") 19 | actual = [] 20 | for label in self.ax.get_xaxis().get_majorticklabels(): 21 | actual.append(label.get_text()) 22 | expected = ['active', 'alco', 'cholesterol', 'gluc', 'overweight', 'smoke'] 23 | self.assertEqual(actual, expected, "Expected bar plot secondary x labels to be 'active', 'alco', 'cholesterol', 'gluc', 'overweight', 'smoke'") 24 | 25 | def test_bar_plot_number_of_bars(self): 26 | actual = len([rect for rect in self.ax.get_children() if isinstance(rect, mpl.patches.Rectangle)]) 27 | expected = 13 28 | self.assertEqual(actual, expected, "Expected a different number of bars chart.") 29 | 30 | 31 | class HeatMapTestCase(unittest.TestCase): 32 | def setUp(self): 33 | self.fig = medical_data_visualizer.draw_heat_map() 34 | self.ax = self.fig.axes[0] 35 | 36 | def test_heat_map_labels(self): 37 | actual = [] 38 | for label in self.ax.get_xticklabels(): 39 | actual.append(label.get_text()) 40 | expected = ['id', 'age', 'sex', 'height', 'weight', 'ap_hi', 'ap_lo', 'cholesterol', 'gluc', 'smoke', 'alco', 'active', 'cardio', 'overweight'] 41 | self.assertEqual(actual, expected, "Expected heat map labels to be 'id', 'age', 'sex', 'height', 'weight', 'ap_hi', 'ap_lo', 'cholesterol', 'gluc', 'smoke', 'alco', 'active', 'cardio', 'overweight'.") 42 | 43 | def test_heat_map_values(self): 44 | actual = [text.get_text() for text in self.ax.get_default_bbox_extra_artists() if isinstance(text, mpl.text.Text)] 45 | print(actual) 46 | expected = ['0.0', '0.0', '-0.0', '0.0', '-0.1', '0.5', '0.0', '0.1', '0.1', '0.3', '0.0', '0.0', '0.0', '0.0', '0.0', '0.0', '0.2', '0.1', '0.0', '0.2', '0.1', '0.0', '0.1', '-0.0', '-0.1', '0.1', '0.0', '0.2', '0.0', '0.1', '-0.0', '-0.0', '0.1', '0.0', '0.1', '0.4', '-0.0', '-0.0', '0.3', '0.2', '0.1', '-0.0', '0.0', '0.0', '-0.0', '-0.0', '-0.0', '0.2', '0.1', '0.1', '0.0', '0.0', '0.0', '0.0', '0.3', '0.0', '-0.0', '0.0', '-0.0', '-0.0', '-0.0', '0.0', '0.0', '-0.0', '0.0', '0.0', '0.0', '0.2', '0.0', '-0.0', '0.2', '0.1', '0.3', '0.2', '0.1', '-0.0', '-0.0', '-0.0', '-0.0', '0.1', '-0.1', '-0.1', '0.7', '0.0', '0.2', '0.1', '0.1', '-0.0', '0.0', '-0.0', '0.1'] 47 | self.assertEqual(actual, expected, "Expected different values in heat map.") 48 | 49 | if __name__ == "__main__": 50 | unittest.main() 51 | --------------------------------------------------------------------------------