“Гистограммы Python matplotlib” можно перевести на английский как “Гистограммы Python matplotlib”. Вот несколько методов создания гистограмм с использованием библиотеки Matplotlib в Python:
-
Метод 1: использование функции
pyplot.bar:import matplotlib.pyplot as plt # Data for the bar chart x = [1, 2, 3, 4, 5] y = [10, 15, 7, 12, 9] # Creating the bar chart plt.bar(x, y) # Customizing the chart plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Bar Chart') plt.show() -
Метод 2. Использование функции
pyplot.barhдля горизонтальных гистограмм:import matplotlib.pyplot as plt # Data for the horizontal bar chart y = [1, 2, 3, 4, 5] x = [10, 15, 7, 12, 9] # Creating the horizontal bar chart plt.barh(y, x) # Customizing the chart plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Horizontal Bar Chart') plt.show() -
Метод 3. Использование массивов NumPy для создания гистограмм с накоплением:
import matplotlib.pyplot as plt import numpy as np # Data for the stacked bar chart categories = ['A', 'B', 'C', 'D', 'E'] values1 = [10, 15, 7, 12, 9] values2 = [8, 11, 9, 6, 15] # Creating the stacked bar chart ind = np.arange(len(categories)) width = 0.35 plt.bar(ind, values1, width, label='Value 1') plt.bar(ind, values2, width, bottom=values1, label='Value 2') # Customizing the chart plt.xlabel('Categories') plt.ylabel('Values') plt.title('Stacked Bar Chart') plt.xticks(ind, categories) plt.legend() plt.show()
Это всего лишь несколько методов создания гистограмм с использованием Matplotlib в Python. Вы можете изучить документацию Matplotlib, чтобы узнать больше о параметрах настройки и продвинутых методах.