1

I have the following data:

[0.21, 0.21, 0.33, 0.52, 0.22, 0.35, 0.43]

I would like to do the following things:

  1. Draw a bar chart like this: enter image description here The x-axis should be 0.21, 0.22, 0.33, 0.35, 0.43, 0.52.

  2. The second things I would like to do is using a value range, for example, I would like to change the x-axis to : 0.01- 0.2, 0.2-0.4, 0.4-0.6 Instead of loop it one by one, is there any smarter way?

1
  • 1
    When you say: "the first X-axis should be 0.21, 0.22, 0.33, 0.35, 0.43, 0.52", do you mean the bins? And for the second I believe you need ax.set_xticks. Commented Aug 9, 2018 at 13:01

1 Answer 1

1

Part 2. of your question is simple enough to do - you just need to define the width of the bins by passing a list of the boundaries.

import matplotlib.pyplot as plt

X = [0.21, 0.21, 0.33, 0.52, 0.22, 0.35, 0.43]
plt.hist(X, bins=[0.0, 0.2, 0.4, 0.6])
plt.show()

This will create bins [0.0, 0.2), [0.2, 0.4), [0.4, 0.6] where '[' is inclusive and '(' is exclusive.

Not clear on what you require in part 1. of your question.

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

1 Comment

The answer to part 1 is basically "plot a histogram with plt.hist".

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.