简体   繁体   中英

Need Help In Matlplotlib Plotting

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).

在此处输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM