python matplot.hist - 删除栏之间的间隙

时间:2018-02-18 16:04:19

标签: python matplotlib histogram

我希望创建一个直方图,条形之间没有间隙。试图添加参数<?php session_start(); include '../database/login-dbh.php'; $email = $_POST['email']; $pwd = $_POST['pwd']; $sql = "SELECT * FROM user WHERE email= ? "; $stmt = mysqli_prepare($conn, $sql); mysqli_stmt_bind_param($stmt, 's', $email); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); $row = mysqli_fetch_assoc($result); if(password_verify($pwd, $row['password'])) { $_SESSION['id'] = $row['id']; $userID = $row['id']; header("Location: ../index.php?id=$userID"); exit(); } else { header("Location: ../index.php?error=login"); exit(); } ?> bin,但没有成功。

range

histogram with gaps between the bars

1 个答案:

答案 0 :(得分:0)

您需要使用bins参数来调整使用哪些容器。

import numpy as np
from matplotlib import pyplot as plt

population = 100
possible_answers = 4
scores = np.random.choice(range(possible_answers),population)
plt.hist(scores, bins=range(possible_answers+1), ec="k")

plt.show()

enter image description here

或者,如果你想转移垃圾箱

plt.hist(scores, bins=np.arange(possible_answers+1)-0.5, ec="k")

enter image description here