import matplotlib.pyplot as plt
import pandas as pd
Line
Plotting one value on a single graph
= [x for x in range(25,36,1)]
dev_x = [38496, 42000, 46752, 49320, 53200, 56000, 62316, 64928, 67317, 68748, 73752] dev_y
plt.plot(dev_x, dev_y)"Median Salary (USD) by Age")
plt.title("Age")
plt.xlabel("Median Salary (USD)") plt.ylabel(
Text(0, 0.5, 'Median Salary (USD)')
Plotting two values on a single graph
= dev_x
age_x = [38496, 42000, 46752, 49320, 53200, 56000, 62316, 64928, 67317, 68748, 73752]
dev_y = [45372, 48476, 53850, 57287, 63016, 65998, 70003, 70000, 71496, 75370, 83640]
pydev_y = [37810, 43515, 46823, 49293, 53437, 56373, 62375, 66674, 68745, 68746, 74583] jsdev_y
plt.plot(age_x, dev_y)
plt.plot(age_x, pydev_y)"Median Salary (USD) by Age")
plt.title("Ages")
plt.xlabel("Median Salary (USD)") plt.ylabel(
Text(0, 0.5, 'Median Salary (USD)')
# Tip1: 플롯에 추가된 순서대로 목록을 전달하여 범례를 추가할 수 있습니다.
plt.plot(age_x, dev_y)
plt.plot(age_x, pydev_y)"Median Salary (USD) by Age")
plt.title("Ages")
plt.xlabel("Median Salary (USD)")
plt.ylabel("All_Developers", "Python_Developers"]) plt.legend([
# Tip2: plt.plot()에 레이블 매개변수 추가하기
= "All_Developers")
plt.plot(age_x, dev_y, label = "Python_Developers")
plt.plot(age_x, pydev_y, label "Ages")
plt.xlabel("Median Salary (USD)")
plt.ylabel("Median Salary (USD) by Age")
plt.title( plt.legend()
"k--", label = "All_Developers")
plt.plot(age_x, dev_y, "b-",label = "Python_Developers")
plt.plot(age_x, pydev_y, "Median Salary (USD) by Age")
plt.title("Ages")
plt.xlabel("Median Salary (USD)")
plt.ylabel( plt.legend()
# 코드 가독성 높이기
= "k", linestyle = "--", label = "All_Developers")
plt.plot(age_x, dev_y, color = "b", linestyle = '-', label = "Python_Developers")
plt.plot(age_x, pydev_y, color "Ages")
plt.xlabel("Median Salary (USD)")
plt.ylabel("Median Salary (USD) by Age")
plt.title( plt.legend()
# 선에 마커 추가하기
= "k", linestyle = "--", marker = ".", label = "All_Developers")
plt.plot(age_x, dev_y, color = "b", linestyle = '-', marker = "o",label = "Python_Developers")
plt.plot(age_x, pydev_y, color "Ages")
plt.xlabel("Median Salary (USD)")
plt.ylabel("Median Salary (USD) by Age")
plt.title( plt.legend()
= "#444444", linestyle = "--", label = "All_Developers")
plt.plot(age_x, dev_y, color = "#5a7d9a", linestyle = '-',label = "Python_Developers")
plt.plot(age_x, pydev_y, color = "#adad3b", linestyle = '-',label = "Java_script_Developers")
plt.plot(age_x, jsdev_y, color "Median Salary (USD) by Age")
plt.title("Ages")
plt.xlabel("Median Salary (USD)")
plt.ylabel( plt.legend()
# 파이썬과 자바스크립트의 너비 변경하기
= "#5a7d9a", linestyle = '-',linewidth = 4, label = "Python_Developers")
plt.plot(age_x, pydev_y, color = "#adad3b", linestyle = '-',linewidth = 4, label = "Java_script_Developers")
plt.plot(age_x, jsdev_y, color = "#444444", linestyle = "--", label = "All_Developers")
plt.plot(age_x, dev_y, color "Median Salary (USD) by Age")
plt.title("Ages")
plt.xlabel("Median Salary (USD)")
plt.ylabel( plt.legend()
# 그래프에 패딩 추가
= "#5a7d9a", linestyle = '-',linewidth = 4, label = "Python_Developers")
plt.plot(age_x, pydev_y, color = "#adad3b", linestyle = '-',linewidth = 4, label = "Java_script_Developers")
plt.plot(age_x, jsdev_y, color = "#444444", linestyle = "--", label = "All_Developers")
plt.plot(age_x, dev_y, color "Median Salary (USD) by Age")
plt.title("Ages")
plt.xlabel("Median Salary (USD)")
plt.ylabel(
plt.legend() plt.tight_layout()
# 플롯에 그리드 추가
= "#5a7d9a", linestyle = '-',linewidth = 4, label = "Python_Developers")
plt.plot(age_x, pydev_y, color = "#adad3b", linestyle = '-',linewidth = 4, label = "Java_script_Developers")
plt.plot(age_x, jsdev_y, color = "#444444", linestyle = "--", label = "All_Developers")
plt.plot(age_x, dev_y, color "Ages")
plt.xlabel("Median Salary (USD)")
plt.ylabel("Median Salary (USD) by Age")
plt.title(
plt.legend()
plt.tight_layout()True) plt.grid(
Using Style!
# 사용 가능한 스타일
plt.style.available
['Solarize_Light2',
'_classic_test_patch',
'_mpl-gallery',
'_mpl-gallery-nogrid',
'bmh',
'classic',
'dark_background',
'fast',
'fivethirtyeight',
'ggplot',
'grayscale',
'seaborn-v0_8',
'seaborn-v0_8-bright',
'seaborn-v0_8-colorblind',
'seaborn-v0_8-dark',
'seaborn-v0_8-dark-palette',
'seaborn-v0_8-darkgrid',
'seaborn-v0_8-deep',
'seaborn-v0_8-muted',
'seaborn-v0_8-notebook',
'seaborn-v0_8-paper',
'seaborn-v0_8-pastel',
'seaborn-v0_8-poster',
'seaborn-v0_8-talk',
'seaborn-v0_8-ticks',
'seaborn-v0_8-white',
'seaborn-v0_8-whitegrid',
'tableau-colorblind10']
# 'fivethirtyeight'
'fivethirtyeight')
plt.style.use(= '-', label = "Python_Developers")
plt.plot(age_x, pydev_y, linestyle = '-', label = "Java_script_Developers")
plt.plot(age_x, jsdev_y, linestyle = "#444444", linestyle = "--", label = "All_Developers")
plt.plot(age_x, dev_y, color "Median Salary (USD) by Age")
plt.title("Ages")
plt.xlabel("Median Salary (USD)")
plt.ylabel(
plt.legend() plt.tight_layout()
# 'ggplot'
'ggplot')
plt.style.use(= '-', label = "Python_Developers")
plt.plot(age_x, pydev_y, linestyle = '-', label = "Java_script_Developers")
plt.plot(age_x, jsdev_y, linestyle = "#444444", linestyle = "--", label = "All_Developers")
plt.plot(age_x, dev_y, color "Median Salary (USD) by Age")
plt.title("Ages")
plt.xlabel("Median Salary (USD)")
plt.ylabel(
plt.legend() plt.tight_layout()
Recap
= [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
ages_x 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55]
= [20046, 17100, 20000, 24744, 30500, 37732, 41247, 45372, 48876, 53850, 57287, 63016, 65998, 70003, 70000, 71496, 75370, 83640, 84666,
py_dev_y 84392, 78254, 85000, 87038, 91991, 100000, 94796, 97962, 93302, 99240, 102736, 112285, 100771, 104708, 108423, 101407, 112542, 122870, 120000]
= [16446, 16791, 18942, 21780, 25704, 29000, 34372, 37810, 43515, 46823, 49293, 53437, 56373, 62375, 66674, 68745, 68746, 74583, 79000,
js_dev_y 78508, 79996, 80403, 83820, 88833, 91660, 87892, 96243, 90000, 99313, 91660, 102264, 100000, 100000, 91660, 99240, 108000, 105000, 104000]
= [17784, 16500, 18012, 20628, 25206, 30252, 34368, 38496, 42000, 46752, 49320, 53200, 56000, 62316, 64928, 67317, 68748, 73752, 77232,
dev_y 78000, 78508, 79536, 82488, 88935, 90000, 90056, 95000, 90000, 91633, 91660, 98150, 98964, 100000, 98988, 100000, 108923, 105000, 103117]
= '-', label = "Python_Developers")
plt.plot(ages_x, py_dev_y, linestyle = '-', label = "Java_script_Developers")
plt.plot(ages_x, js_dev_y, linestyle = "#444444", linestyle = "--", label = "All_Developers")
plt.plot(ages_x, dev_y, color "Ages")
plt.xlabel("Median Salary (USD)")
plt.ylabel("Median Salary (USD) by Age")
plt.title(
plt.legend() plt.tight_layout()
= [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
ages_x 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55]
= [20046, 17100, 20000, 24744, 30500, 37732, 41247, 45372, 48876, 53850, 57287, 63016, 65998, 70003, 70000, 71496, 75370, 83640, 84666,
py_dev_y 84392, 78254, 85000, 87038, 91991, 100000, 94796, 97962, 93302, 99240, 102736, 112285, 100771, 104708, 108423, 101407, 112542, 122870, 120000]
= [16446, 16791, 18942, 21780, 25704, 29000, 34372, 37810, 43515, 46823, 49293, 53437, 56373, 62375, 66674, 68745, 68746, 74583, 79000,
js_dev_y 78508, 79996, 80403, 83820, 88833, 91660, 87892, 96243, 90000, 99313, 91660, 102264, 100000, 100000, 91660, 99240, 108000, 105000, 104000]
= [17784, 16500, 18012, 20628, 25206, 30252, 34368, 38496, 42000, 46752, 49320, 53200, 56000, 62316, 64928, 67317, 68748, 73752, 77232,
dev_y 78000, 78508, 79536, 82488, 88935, 90000, 90056, 95000, 90000, 91633, 91660, 98150, 98964, 100000, 98988, 100000, 108923, 105000, 103117]
"ggplot")
plt.style.use(= '-', label = "Python_Developers")
plt.plot(ages_x, py_dev_y, linestyle = '-', label = "Java_script_Developers")
plt.plot(ages_x, js_dev_y, linestyle = "#444444", linestyle = "--", label = "All_Developers")
plt.plot(ages_x, dev_y, color "Ages")
plt.xlabel("Median Salary (USD)")
plt.ylabel("Median Salary (USD) by Age")
plt.title(
plt.legend() plt.tight_layout()
= [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
ages_x 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55]
= [20046, 17100, 20000, 24744, 30500, 37732, 41247, 45372, 48876, 53850, 57287, 63016, 65998, 70003, 70000, 71496, 75370, 83640, 84666,
py_dev_y 84392, 78254, 85000, 87038, 91991, 100000, 94796, 97962, 93302, 99240, 102736, 112285, 100771, 104708, 108423, 101407, 112542, 122870, 120000]
= [16446, 16791, 18942, 21780, 25704, 29000, 34372, 37810, 43515, 46823, 49293, 53437, 56373, 62375, 66674, 68745, 68746, 74583, 79000,
js_dev_y 78508, 79996, 80403, 83820, 88833, 91660, 87892, 96243, 90000, 99313, 91660, 102264, 100000, 100000, 91660, 99240, 108000, 105000, 104000]
= [17784, 16500, 18012, 20628, 25206, 30252, 34368, 38496, 42000, 46752, 49320, 53200, 56000, 62316, 64928, 67317, 68748, 73752, 77232,
dev_y 78000, 78508, 79536, 82488, 88935, 90000, 90056, 95000, 90000, 91633, 91660, 98150, 98964, 100000, 98988, 100000, 108923, 105000, 103117]
"fivethirtyeight")
plt.style.use(= '-', label = "Python_Developers")
plt.plot(ages_x, py_dev_y, linestyle = '-', label = "Java_script_Developers")
plt.plot(ages_x, js_dev_y, linestyle = "#444444", linestyle = "--", label = "All_Developers")
plt.plot(ages_x, dev_y, color "Median Salary (USD) by Age")
plt.title("Ages")
plt.xlabel("Median Salary (USD)")
plt.ylabel(
plt.legend() plt.tight_layout()
Line and Fill!
= pd.read_csv("data/salary.csv")
data data.head()
Age | All_Devs | Python | JavaScript | |
---|---|---|---|---|
0 | 18 | 17784 | 20046 | 16446 |
1 | 19 | 16500 | 17100 | 16791 |
2 | 20 | 18012 | 20000 | 18942 |
3 | 21 | 20628 | 24744 | 21780 |
4 | 22 | 25206 | 30500 | 25704 |
= data["Age"]
ages = data["All_Devs"]
dev_salaries = data["Python"]
py_salaries = data["JavaScript"] js_salaries
"ggplot")
plt.style.use(= "#444444", linestyle = '--', label = "All Devs")
plt.plot(ages, dev_salaries, color = "Python")
plt.plot(ages, py_salaries, label
plt.legend() plt.tight_layout()
# 채우기
"ggplot")
plt.style.use(= "#444444", linestyle = '--', label = "All Devs")
plt.plot(ages, dev_salaries, color = "Python")
plt.plot(ages, py_salaries, label
plt.fill_between(ages, py_salaries)
plt.legend() plt.tight_layout()
"ggplot")
plt.style.use(= "#444444", linestyle = '--', label = "All Devs")
plt.plot(ages, dev_salaries, color = "Python")
plt.plot(ages, py_salaries, label = 0.5)
plt.fill_between(ages, py_salaries, alpha
plt.legend() plt.tight_layout()
= 57287
overall_median "ggplot")
plt.style.use(= "#444444", linestyle = '--', label = "All Devs")
plt.plot(ages, dev_salaries, color = "Python")
plt.plot(ages, py_salaries, label =(py_salaries > overall_median), interpolate = True, alpha = 0.5)
plt.fill_between(ages, py_salaries, overall_median, where
plt.legend() plt.tight_layout()
= 57287
overall_median "ggplot")
plt.style.use(= "#444444", linestyle = '--', label = "All Devs")
plt.plot(ages, dev_salaries, color = "Python")
plt.plot(ages, py_salaries, label =(py_salaries > overall_median), interpolate = True, alpha = 0.5)
plt.fill_between(ages, py_salaries, overall_median, where= (py_salaries < overall_median), interpolate = True, alpha = 0.25)
plt.fill_between(ages, py_salaries, overall_median, where
plt.legend() plt.tight_layout()
# 채우기 색상 사용자 지정
"ggplot")
plt.style.use(= "#444444", linestyle = '--', label = "All Devs")
plt.plot(ages, dev_salaries, color = "Python")
plt.plot(ages, py_salaries, label = 57287
overall_median =(py_salaries > overall_median), interpolate = True, alpha = 0.5)
plt.fill_between(ages, py_salaries, overall_median, where=(py_salaries < overall_median), color = "green", interpolate = True, alpha = 0.25)
plt.fill_between(ages, py_salaries, overall_median, where
plt.legend() plt.tight_layout()
= 57287
overall_median "ggplot")
plt.style.use(= "#444444", linestyle = '--', label = "All Devs")
plt.plot(ages, dev_salaries, color = "Python")
plt.plot(ages, py_salaries, label = (py_salaries > dev_salaries), interpolate = True, alpha = 0.5)
plt.fill_between(ages, py_salaries, dev_salaries, where = (py_salaries < dev_salaries), color = "green", interpolate = True, alpha = 0.25)
plt.fill_between(ages, py_salaries, overall_median, where
plt.legend() plt.tight_layout()
= 57287
overall_median "ggplot")
plt.style.use(= "#444444", linestyle = '--', label = "All Devs")
plt.plot(ages, dev_salaries, color = "Python")
plt.plot(ages, py_salaries, label = (py_salaries > dev_salaries), interpolate = True, alpha = 0.5, label = "above dev_sal")
plt.fill_between(ages, py_salaries, dev_salaries, where = (py_salaries < dev_salaries), color = "green", interpolate = True, alpha = 0.25, label = "below dev_sal")
plt.fill_between(ages, py_salaries, overall_median, where
plt.legend() plt.tight_layout()