This builds on the earlier Python Bar Chart. Differences are highlighted below.
- Same as Python Bar Chart.
- Display a numbered list of available players in the data, with a 0 for exiting.
- Iterate through
data
, adding player names to a list. After that, convert the list to a dictionary, which automatically removes all duplicates, then convert back to a list, and sort. - Request for input to select a player.
- Utilize a
Try-catch
to ensure only numerical data is entered. - If value is numerical but out of bounds, do-over.
- If value is 0, end program.
- Utilize a
- Use the selected player to generate the line chart.
We use the matplotlib
library to plot the line chart, and the numpy
library to access aggregation functions.
- An average line can be drawn using the
axhline()
method frommatplotlib
, using as an argument a value derived from using thenanmean()
method ofnumpy
. - Goals and appearances are represented using different colors.
- Averages are represented using dashed lines.
- The labels for goals and appearances are placed above the average lines.