I'm trying to create a dot plot/dot chart based on students' hours of sleep, but the closest I was able to get was a histogram which matched my data. The method I tried which will be provided below didn't work for me either due to my sheer inexperience or incompatibility with my data. Any help would be greatly appreciated.
I've already tried a similar answer which was this: How to create a "dot plot" in Matplotlib? (not a scatter plot)
This method rounded the float values in hours of sleep up, which was making the plot incorrect, or perhaps I was just using it wrong. I would appreciate a solution using my exact example, because I'm still pretty new to programming and likely won't understand much else.
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
hours_of_sleep = [9, 6 ,8, 6, 8, 8, 6, 6.5, 6, 7, 9, 4, 3, 4, 5, 6, 11, 6, 3, 6, 6, 10, 7, 8, 4.5, 9, 7, 7]
bin_list = []
for number in hours_of_sleep:
if number not in bin_list:
bin_list.append(number)
bin_list.sort()
item_1 = bin_list[0]
item_2 = bin_list[-1]
proper_bin = np.arange(item_1, item_2+1, 0.5)
plt.hist([hours_of_sleep], bins=proper_bin, rwidth= 0.8)
plt.title('Hours of Sleep for Students')
plt.show()
I want to end up with something similar to the dot plot example provided by the user who asked the question in the link I've already provided.