0

I'm learning Python by redoing my Excel analyses in Python but can't find a way to plot a histogram with over and under limits.

Here is what the histogram looks like in Excel and what I'm trying to replicate: Excel histogram

And here is what I got in Python: Python histogram

Here is my the actual code:

returns = [r for r in df.Returns.tolist() if np.isnan(r)==False]
plt.hist(returns, bins=20, range=(-10, 10), rwidth=0.8)
plt.show()

The reason why I added this range limit is to have an "incremental" histogram (combined with this number of bins).

As you can see, my Excel histogram has a <= -10% and >10% bar on the leftmost and rightmost side, but my Python histogram does not.

I can only think of 2 other ways to solve this issue:

  1. Manually plotting the histogram which is extremely inconvenient, especially if the number of bin increases

  2. Counting the number of values under/over the limits and inserting the bar into the histogram. But I was unable to find a way to do so

I suppose there must be a simpler way to do this?

iSkyun
  • 1
  • 1

0 Answers0