matplotlib.pyplot plt.hist()画直方图时x坐标刻度和图不对齐的问题(已解决) 您所在的位置:网站首页 stata直方图横轴刻度 matplotlib.pyplot plt.hist()画直方图时x坐标刻度和图不对齐的问题(已解决)

matplotlib.pyplot plt.hist()画直方图时x坐标刻度和图不对齐的问题(已解决)

2024-06-03 12:30| 来源: 网络整理| 查看: 265

我的数据是随机投掷10,000次骰子

uni_data = np.random.randint(1, 7, 10000)

画直方图

plt.hist(uni_data,edgecolor='w',density=1) plt.show()

在这里插入图片描述

tcl柱子和图对不齐,解决:修改bins和x范围

plt.hist(uni_data,bins=np.arange(0.5,7.5), edgecolor='w',density=1) plt.show()

ps:(0.5,7.5)默认步长为1,因为np.arange不会统计最后一个区间即(6.5,7.5),取.5是为了保证刻度在柱子的中间

bins=np.arange(0.5,7.5)等效于bins=np.arange(1,8)-0.5,也等效于bins=np.arange(8)-0.5 plt.xlim(0,7) 在这里插入图片描述



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有