Is it possible to make the pitch of the Ox axis to a certain value to be small, and after - to large?

My situation: I build a histogram, where most of the data lie in a small interval [0-100], but there are some extreme values ​​(1500,2000, etc.), so the Ox axis expands and I get merging high bars at the beginning, a large pass and very small bars in the region of extreme values. It is necessary that at first the columns were visible (for example, in increments of 5), and then the range [100-2000] was one column.

I use the plt.hist() method.

Screen of current behavior for:

 x = [1, 1, 1, 2, 2, 4, 4, 4, 5, 1000, 2000] bins = [1, 2, 4, 5, 1000, 2000] 

enter image description here

  • Please indicate in the question the code that you have at the moment - an attempt to solve and an example of input data. From the wording of the question it is not clear exactly how you want to build histograms - what should be the ranges ( bins ) - MaxU
  • @MaxU Well, I wrote everything: a lot of numbers from the range [1-100] should fall into a large number of bins (in increments of 5 it turns out 20 pieces), and then 1 bin for the range [100-2000] for extreme values - level
  • @MaxU input data is very large, you can randomly generate 10,000 values ​​from [1-100] and 10 values ​​from [1000-2000] - level
  • @MaxU code at the moment plt.hist(x, bins) , where bins is a fixed number, x is all the data in the list - level
  • @MaxU added a screen with an example, it is necessary that the left columns are normally distinguishable, and the right ones are not so wide - level

1 answer 1

Try this:

 import numpy as np import pandas as pd # randomly generated data a = np.random.randint(101, size=10000) b = np.random.randint(1500, 2001, size=20) x = pd.Series(np.concatenate((a,b))) # custom binning ... bins = np.concatenate((np.arange(0, 105, 5), [1500, 2001])) labels = np.concatenate((np.arange(5, 105, 5).astype(str), ['100-1500', '1500-2000'])) r = x.groupby(pd.cut(x, bins=bins, labels=labels, include_lowest=True)).size() # plotting ... r[r>0].plot.bar(rot=0, figsize=(12, 4), grid=True) plt.tight_layout() 

enter image description here