Как нормализовать гистограмму в питоне?
Я пытаюсь построить нормированную гистограмму, но вместо того, чтобы получать 1 как максимальное значение по оси y, я получаю разные числа.
Для массива k = (1,4,3,1)
Я получаю эту гистограмму, которая не выглядит нормированной.

Для другого массива k = (3,3,3,3)
Я получаю эту гистограмму с максимальным значением y 10.

При разных k получается разное максимальное значение y, хотя нормированное = 1 или нормированное = True.
Почему нормализация (если она работает) изменяется на основе данных и как я могу сделать максимальное значение y равным 1?
UPDATE:
Я пытаюсь выполнить Carsten König ответ из построения гистограмм, высота баров которых равна 1 в matplotlib и получить очень странный результат:
Create a Normalized Histogram Using Python Matplotlib

A histogram is a frequency distribution that depicts the frequencies of different elements in a dataset. This graph is generally used to study frequencies and determine how the values are distributed in a dataset.
Please enable JavaScript
Normalization of histogram refers to mapping the frequencies of a dataset between the range [0, 1] both inclusive. In this article, we will learn how to create a normalized histogram in Python.
Create a Normalized Histogram Using the Matplotlib Library in Python
The Matplotlib module is a comprehensive Python module for creating static and interactive plots. It is a very robust and straightforward package that is widely used in data science for visualization purposes. Matplotlib can be used to create a normalized histogram. This module has a hist() function. that is used for creating histograms. Following is the function definition of the hist() method.
- x : A list, a tuple, or a NumPy array of input values.
- density : A boolean flag for plotting normalized values. By default, it is False .
- color : The colour of the bars in the histogram.
- label : A label for the plotted values.
Refer to the following Python code to create a normalized histogram.
Vaibhav is an artificial intelligence and cloud computing stan. He likes to build end-to-end full-stack web and mobile applications. Besides computer science and technology, he loves playing cricket and badminton, going on bike rides, and doodling.
Русские Блоги
Два способа нарисовать и подогнать нормальную кривую распределения для гистограммы с помощью Python
Гистограмма представляет собой график, используемый для отображения распределения данных по группам. Ширина и высота прямоугольника используются для представления распределения частот. С помощью гистограммы пользователи могут интуитивно видеть форму распределения данных, центральное положение и степень дисперсии данных. ,
В Python история библиотеки Matplotlib обычно используется для рисования гистограмм. Что касается того, как добавить подгоночную кривую (кривую функции плотности) к гистограмме, обычно есть следующие два метода.
Способ 1: использовать модуль mlab в matplotlib
Модуль mlab — это мощный инструмент для трехмерного рисования в Python, который обладает отличным трехмерным эффектом. Здесь с помощью mlab можно выпрыгнуть из ограничения двухмерного графика гистограммы, а затем добавить еще одну кривую на этой основе. Здесь мы берем данные в радужной оболочке в качестве примера для иллюстрации.

Способ второй: рисовать используя distplot в библиотеке Seaborn
Seaborn на самом деле является более продвинутым пакетом API, основанным на matplotlib, который облегчает рисование. В большинстве случаев использование seaborn может сделать очень привлекательные рисунки, в то время как использование matplotlib может сделать больше Показанная фигура. Seaborn следует рассматривать как дополнение к matplotlib, а не заменитель.
How to normalize an histogram
I have this histogram which counts the array «d» in equally log-spaced bins.
The problem is that I want it to be normalized so as the area is one. Using the option Normed=True I didn’t get the result, it might be due to fact that I’m using logarithmic bins. Therefore I tried normalizing the histogram in this way:
But then I don’t know how to plot H_norm versus the bins
2 Answers 2
I tried normed=True, and the area is 1:
can you run the code, and check the output. If it is not 1, check your numpy version. I got this warning message when run the code: