0

I am trying to plot a histogram

 import matplotlib.pyplot as plt
 import numpy as np
 v = ['1302.42', '7.85422', '21.0631', '6956.37', '10000', '10000', '7312.88', '7708.98', '8421.12', '7419.41',
     '1952.47', '6762.42', '10000', '4057.73', '2051.06', '10000']

    plt.hist(v, bins=np.linspace(0, 10000, 11))
    plt.xticks(rotation=90)
    plt. set(ylabel='Frequency')
    plt.show()
    

enter image description here

The plot doesn't appear right. I am not sure if the bin specification is correct. I am trying to set an interval of 1000. The actual values range from 0 to 10000.

Suggestions on how to fix this will be really helpful.

1 Answer 1

1

Looks fine, you just need to convert your strings into floats:

v = [float(v) for v in [
      '1302.42', '7.85422', '21.0631', '6956.37', '10000', '10000', '7312.88', 
      '7708.98', '8421.12', '7419.41', '1952.47', '6762.42', '10000', '4057.73', '2051.06', 
         '10000']]

And then the rest of the code is identical.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.