0

I am given a dataset and I am supposed to plot: How much does each player get paid per game on average?

I converted the dataset into a NumPy array:

Salary = np.array([KobeBryant_Salary, JoeJohnson_Salary, LeBronJames_Salary, 
                   CarmeloAnthony_Salary, DwightHoward_Salary, ChrisBosh_Salary, 
                   ChrisPaul_Salary, KevinDurant_Salary, DerrickRose_Salary, 
                   DwayneWade_Salary])
Games = np.array([KobeBryant_G, JoeJohnson_G,LeBronJames_G, CarmeloAnthony_G, 
                  DwightHoward_G, ChrisBosh_G, ChrisPaul_G, KevinDurant_G, 
                  DerrickRose_G, DwayneWade_G])

After that, I wrote a for loop, and iterated through this array:

for i in range(0,10):
    plt.plot(Salary[i]/Games[i])

Since one of the players had played 0 games it is showing the ZeroDivisionError in my plot. I wanted to know is this the right approach? Also if it is correct can I please how can I format the y axis so that the lower values are visible better (I tried playing with yticks but it didn't help much).

enter image description here

Muhammad Mohsin Khan
  • 1,444
  • 7
  • 16
  • 23

1 Answers1

1

I ran your code. It does not throw any ZeroDivisionError, rather throws a warning. For improving the visibility of the results, you should use plt.yscale("log") so that lower values will be visible.

Muhammad Mohsin Khan
  • 1,444
  • 7
  • 16
  • 23
  • 1
    Thanks A Lot, Scaling Is Much Better: https://imgur.com/a/deLM9I1 . Is my approach fine, asking this because we are passing only one argument into plot() while we are supposed to pass 2 arguments. – code_till_u_die Jan 28 '22 at 08:33
  • Its a matter of what you want to show on the x-axis? If you want to show the number of games played then you need to put an array on the x-axis accordingly. I am sure that you want to show salary on the y-axis. Right now the plot is just showing `range(0,10)` on the x-axis. – Muhammad Mohsin Khan Jan 28 '22 at 08:37
  • Like nothing is specified as such, i am just trying to learn things. As per my understanding right now the x axis is showing the iteration range while the y axis is showing salary/game. So in order to get like year on the x-axis we need to pass an array of years, salary/game ? – code_till_u_die Jan 28 '22 at 08:49
  • 1
    Yes, that's what I exactly said and that's what you exactly should do :). – Muhammad Mohsin Khan Jan 28 '22 at 08:52