5.5 Dot Plot
# dotplot by Patrick FitzGerald
def dotplots(x,x_label="Data Values"): # function name is dotplots takes a x
import numpy as np
import matplotlib.pyplot as plt
data = np.array(x) # convert to array
values, counts = np.unique(data, return_counts=True)
# dot plot with appropriate figure size and y-axis limits
fig, ax = plt.subplots(figsize=(6, 2.25))
for value, count in zip(values, counts):
ax.plot([value]*count, list(range(count)), 'co', ms=10, linestyle='')
for spine in ['top', 'right', 'left']:
ax.spines[spine].set_visible(False)
ax.yaxis.set_visible(False)
ax.set_ylim(-1, max(counts))
ax.set_xticks(range(min(values), max(values)+1))
ax.tick_params(axis='x', length=0, pad=8, labelsize=12)
plt.suptitle("Dot Plot")
plt.ylabel("frequency")
plt.xlabel("values(categories)")
return plt.show()
Lab 5.5.1
The dataset below is the waiting time, in minutes, of customers at a fast food restaurant. Use the dotplots function to construct a dot plot.
6, 4, 4, 2, 1, 3, 5, 2, 4, 2, 5, 4, 4, 7, 4, 3, 4, 1, 2, 5
Adapted from Python for Introductory Statistics: Student's Lab Workbook, by Simon Aman (Truman College, City Colleges of Chicago), licensed under CC BY 4.0. Changes were made: reformatted as an accessible XYZ web edition with live in-browser code cells. License: CC-BY-4.0.