Чтобы построить гистограмму атрибута «пол» с использованием Matplotlib с интервалами = 2 и rwidth = 0,85, вы можете выполнить следующие шаги:
Метод 1: использование NumPy и Matplotlib
import numpy as np
import matplotlib.pyplot as plt
# Assuming 'sex' is a list or array containing the data
# Create the histogram
plt.hist(sex, bins=2, rwidth=0.85)
# Set the x-axis label and y-axis label
plt.xlabel('Sex')
plt.ylabel('Frequency')
# Set the title of the histogram
plt.title('Histogram of Sex')
# Show the histogram
plt.show()
Метод 2: использование Pandas и Matplotlib
import pandas as pd
import matplotlib.pyplot as plt
# Assuming 'sex' is a Pandas Series or DataFrame column
# Create the histogram
plt.hist(sex, bins=2, rwidth=0.85)
# Set the x-axis label and y-axis label
plt.xlabel('Sex')
plt.ylabel('Frequency')
# Set the title of the histogram
plt.title('Histogram of Sex')
# Show the histogram
plt.show()
Метод 3: использование Seaborn и Matplotlib
import seaborn as sns
import matplotlib.pyplot as plt
# Assuming 'sex' is a list, array, or Pandas Series
# Create the histogram
sns.histplot(sex, bins=2, kde=False)
# Set the x-axis label and y-axis label
plt.xlabel('Sex')
plt.ylabel('Frequency')
# Set the title of the histogram
plt.title('Histogram of Sex')
# Show the histogram
plt.show()
Обратите внимание, что код предполагает, что у вас установлены необходимые библиотеки (например, Matplotlib, NumPy, Pandas, Seaborn) и что переменная «sex» содержит данные, которые вы хотите отобразить.