Plotting in Jupyter Notebook¶
In [104]:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
Section 1: Plotting Math functions¶
In [105]:
#directions: plot two math functions together in the same plot, using two different colors and different line styles, and label the plots, axis.
x = np.linspace(-2, 2, 100)
y1 = np.sin(x) #two math functions
y2 = x**3
plt.plot(x, y1, color='orange', linestyle='-.', label='y = sin(x)') #different line colors, styles, labels
plt.plot(x, y2, color='purple', linestyle=':', label='y = x³')
plt.title('y = sin(x) with y = x³')
plt.xlabel('x-axis') #axis
plt.ylabel('y-axis')
plt.legend()
plt.show()
Section 2: Making Pie Charts of Data in Excel¶
In [106]:
male_new_cases = pd.read_excel(r"C:\Users\QBPAM\Downloads\BigData AI Cancer class by Yongmei Wang\Group-Training-Male-Cancer-statistics.xlsx", sheet_name = "Estimated New Cases")
male_new_cases
Out[106]:
Unnamed: 0 | Male | % | |
---|---|---|---|
0 | Prostate | 299010 | 29 |
1 | Lung & bronchus | 116310 | 11 |
2 | Colon & rectum | 81540 | 8 |
3 | Urinary bladder | 63070 | 6 |
4 | Melanoma of the skin | 59170 | 6 |
5 | Kidney & renal pelvis | 52380 | 5 |
6 | Non-Hodgkin lymphoma | 44590 | 4 |
7 | Oral cavity & pharynx | 41510 | 4 |
8 | Leukemia | 36450 | 4 |
9 | Pancreas | 34530 | 3 |
In [107]:
categories = male_new_cases['Unnamed: 0']
sizes = male_new_cases['%']
plt.figure(figsize = (8,8))
plt.pie(sizes, labels = categories, autopct = '%1.1f%%', startangle = 90) #autopct formats the numbers
plt.axis('equal') #makes the circle perfectly round
plt.title('Statistics of Estimated New Male Cases')
plt.show()
In [108]:
male_deaths = pd.read_excel(r"C:\Users\QBPAM\Downloads\BigData AI Cancer class by Yongmei Wang\Group-Training-Male-Cancer-statistics.xlsx", sheet_name = "Estimated Deaths")
male_deaths
Out[108]:
Unnamed: 0 | Male | % | |
---|---|---|---|
0 | Lung & bronchus | 65790 | 20 |
1 | Prostate | 35250 | 11 |
2 | Colon & rectum | 28700 | 9 |
3 | Pancreas | 27270 | 8 |
4 | Liver & intrahepatic bile duct | 19120 | 6 |
5 | Leukemia | 13640 | 4 |
6 | Esophagus | 12880 | 4 |
7 | Urinary bladder | 12290 | 4 |
8 | Non-Hodgkin lymphoma | 11780 | 4 |
9 | Brain & other nervous system | 10690 | 3 |
In [109]:
categories1 = male_deaths['Unnamed: 0']
sizes1 = male_deaths['%']
plt.figure(figsize = (8,8))
plt.pie(sizes1, labels = categories1, autopct = '%1.1f%%', startangle = 90)
plt.axis('equal')
plt.title('Statistics of Estimated Male Deaths')
plt.show()
In [110]:
female_new_cases = pd.read_excel(r"C:\Users\QBPAM\Downloads\BigData AI Cancer class by Yongmei Wang\Female-Cancer-Statistics.xlsx", sheet_name = "Estimated New Cases")
female_new_cases
Out[110]:
Unnamed: 0 | Female | % | |
---|---|---|---|
0 | Breast | 310720 | 32 |
1 | Lung & bronchus | 118270 | 12 |
2 | Colon & rectum | 71270 | 7 |
3 | Uterine corpus | 67880 | 7 |
4 | Melanoma of the skin | 41470 | 4 |
5 | Non-Hodgkin lymphoma | 36030 | 4 |
6 | Pancreas | 31910 | 3 |
7 | Thyroid | 31520 | 3 |
8 | Kidney & renal pelvis | 29230 | 3 |
9 | Leukemia | 26320 | 3 |
In [111]:
categories2 = female_new_cases['Unnamed: 0']
sizes2 = female_new_cases['%']
plt.figure(figsize = (8,8))
plt.pie(sizes2, labels = categories2, autopct = '%1.1f%%', startangle = 90)
plt.axis('equal')
plt.title('Statistics of Estimated New Female Cases')
plt.show()
In [112]:
female_deaths = pd.read_excel(r"C:\Users\QBPAM\Downloads\BigData AI Cancer class by Yongmei Wang\Female-Cancer-Statistics.xlsx", sheet_name = "Estimated Deaths")
female_deaths
Out[112]:
Unnamed: 0 | Female | % | |
---|---|---|---|
0 | Lung & bronchus | 59280 | 21 |
1 | Breast | 42250 | 15 |
2 | Pancreas | 24480 | 8 |
3 | Colon & rectum | 24310 | 8 |
4 | Uterine corpus | 13250 | 5 |
5 | Ovary | 12740 | 4 |
6 | Liver & intrahepatic bile duct | 10720 | 4 |
7 | Leukemia | 10030 | 3 |
8 | Non-Hodgkin lymphoma | 8360 | 3 |
9 | Brain & other nervous system | 8070 | 3 |
In [113]:
categories3 = female_deaths['Unnamed: 0']
sizes3 = female_deaths['%']
plt.figure(figsize = (8,8))
plt.pie(sizes3, labels = categories3, autopct = '%1.1f%%', startangle = 90)
plt.axis('equal')
plt.title('Statistics of Estimated Female Deaths')
plt.show()
In [ ]: