The choice of the histograms of the Matplotlib matrix depends on whether the data is built "alone" or with some other data: how is this?

There is a title. :)

Example:

from numpy import random from matplotlib import pyplot as plt data = [1 + random.randn(1000), random.randn(1000)] bins = 10 plt.hist(data, bins, label=['first', 'second']) plt.hist(data[1], bins, histtype='step', label=['second again']) plt.legend() plt.show() 

gives (the type "step" is selected to help "visibility", the same with the default values):

the damn thing;)

Cm?

+4
source share
2 answers

Here is the process that hist is currently using (in matplotlib git repo) to determine the beans:

  • If bins are specified as actual cells, these bins will be used
  • If bin_range is specified, then these two values ​​will be used for bin_range.
  • If bin_range is not set, use [min of all data, maximum of all data] as bin_range.
  • Use the numpy histogram function on each dataset with bin_range parameters and bins. However, the cells are replaced with what comes out of the histogram. This means that the boxes are ultimately defined in the first example from two sets of input data by calling the numpy histogram with bins = 10 and bin_range = [min of all data, maximum of all data] in the first data set.

As you can imagine, it is not surprising that you will get a different set of bins for using a histogram with one data set, another data set and both together with these criteria, because bin_range will probably be different in all three instances.

+4
source

Well, no one said that the boxes will be the same for different ranges of values ​​along the x axis;)

Here it is (see accepted answer):

 from numpy import random from matplotlib import pyplot as plt data = [1 + random.randn(1000), random.randn(1000)] num_bins = 10 _n, bins, _patches = plt.hist(data, num_bins, label=['first', 'second']) plt.hist(data[1], bins, histtype='step', label=['second again']) plt.legend() plt.show() 

giving:

enter image description here

+2
source

Source: https://habr.com/ru/post/1386708/


All Articles