以下是一个使用Python的Matplotlib库来绘制不同直方图分箱的边缘图的示例代码:
import numpy as np
import matplotlib.pyplot as plt
# 生成随机数据
np.random.seed(0)
x = np.random.randn(1000)
y = np.random.randn(1000)
# 设置直方图分箱数目
num_bins = 20
# 绘制x轴直方图
fig, axs = plt.subplots(2, 1, sharex=True, sharey=True, figsize=(6, 6))
axs[0].hist(x, bins=num_bins, color='red', alpha=0.5)
axs[0].set_ylabel('Frequency')
# 绘制y轴直方图
axs[1].hist(y, bins=num_bins, color='blue', alpha=0.5)
axs[1].set_xlabel('Value')
axs[1].set_ylabel('Frequency')
# 添加标题和网格线
plt.suptitle('Joint Histogram with Different Histogram Bins')
plt.grid(True)
# 显示图形
plt.show()
运行以上代码会生成一个包含两个子图的图形,上面的子图显示了x轴数据的直方图,下面的子图显示了y轴数据的直方图。你可以根据需要调整直方图的分箱数目和颜色等参数。
下一篇:不同的智能手机上布局显示不正确。