| Line 2: |
Line 2: |
| | https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html | | https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html |
| | | | |
| − | == Cheatsheets == | + | ==Cheatsheets== |
| | https://s3.amazonaws.com/assets.datacamp.com/blog_assets/Python_Matplotlib_Cheat_Sheet.pdf | | https://s3.amazonaws.com/assets.datacamp.com/blog_assets/Python_Matplotlib_Cheat_Sheet.pdf |
| | | | |
| Line 36: |
Line 36: |
| | plt.tight_layout() | | plt.tight_layout() |
| | plt.savefig('plot.png') | | plt.savefig('plot.png') |
| | + | plt.show() |
| | + | </syntaxhighlight> |
| | + | |
| | + | ==== Fill between ==== |
| | + | <syntaxhighlight lang="python3"> |
| | + | import pandas as pd |
| | + | from matplotlib import pyplot as plt |
| | + | |
| | + | data = pd.read_csv('data.csv') |
| | + | ages = data['Age'] |
| | + | dev_salaries = data['All_Devs'] |
| | + | py_salaries = data['Python'] |
| | + | js_salaries = data['JavaScript'] |
| | + | |
| | + | plt.plot(ages, dev_salaries, color='#444444', |
| | + | linestyle='--', label='All Devs') |
| | + | |
| | + | plt.plot(ages, py_salaries, label='Python') |
| | + | |
| | + | overall_median = 57287 |
| | + | |
| | + | plt.fill_between(ages, py_salaries, dev_salaries, |
| | + | where=(py_salaries > dev_salaries), |
| | + | interpolate=True, alpha=0.25, label='Above Avg') |
| | + | |
| | + | plt.fill_between(ages, py_salaries, dev_salaries, |
| | + | where=(py_salaries <= dev_salaries), |
| | + | interpolate=True, color='red', alpha=0.25, label='Below Avg') |
| | + | |
| | + | plt.legend() |
| | + | |
| | + | plt.title('Median Salary (USD) by Age') |
| | + | plt.xlabel('Ages') |
| | + | plt.ylabel('Median Salary (USD)') |
| | + | |
| | + | plt.tight_layout() |
| | + | |
| | plt.show() | | plt.show() |
| | </syntaxhighlight> | | </syntaxhighlight> |