如何在单个 y 刻度上绘制散点图
How to plot a scatter plot on a single y-tick
我只是想知道是否有任何 python 包可用于在单个轴上绘制散点图。我乐于接受新的想法和方法,并希望在开始之前试探一下
是否可以用 Python 绘制上面的图如果是,将使用哪个包来绘制上面的图?有人可以阐明用 Python 绘制上述图吗?我很乐意收到您的任何线索。
示例集:
timeData = ['2009/6/12 5:00', '2009/6/12 7:00', '2009/6/12 9:00', '2009/6/12 13:00', '2009/6/12 15:00', '2009/6/12 17:00', '2009/6/12 21:00', '2009/6/13 1:00', '2009/6/13 5:00', '2009/6/13 7:00', '2009/6/13 9:00', '2009/6/13 13:00', '2009/6/13 15:00', '2009/6/13 17:00', '2009/6/13 21:00', '2009/6/14 1:00', '2009/6/14 5:00', '2009/6/14 7:00', '2009/6/14 9:00', '2009/6/14 13:00', '2009/6/14 15:00', '2009/6/14 17:00', '2009/6/14 21:00', '2009/6/15 1:00', '2009/6/15 5:00', '2009/6/15 7:00', '2009/6/15 9:00', '2009/6/15 13:00', '2009/6/15 15:00', '2009/6/15 17:00', '2009/6/15 21:00', '2009/6/16 1:00', '2009/6/16 5:00', '2009/6/16 7:00', '2009/6/16 9:00', '2009/6/16 13:00', '2009/6/16 15:00', '2009/6/16 17:00', '2009/6/16 21:00', '2009/6/17 1:00', '2009/6/17 5:00', '2009/6/17 7:00', '2009/6/17 9:00', '2009/6/17 13:00', '2009/6/17 15:00', '2009/6/17 17:00', '2009/6/17 21:00', '2009/6/18 1:00', '2009/6/18 5:00', '2009/6/18 7:00', '2009/6/18 9:00', '2009/6/18 13:00', '2009/6/18 15:00', '2009/6/18 17:00', '2009/6/18 21:00', '2009/6/19 1:00', '2009/6/19 5:00', '2009/6/19 7:00', '2009/6/19 9:00', '2009/6/19 13:00', '2009/6/19 15:00', '2009/6/19 17:00', '2009/6/19 21:00', '2009/6/20 1:00', '2009/6/20 5:00', '2009/6/20 7:00', '2009/6/20 9:00', '2009/6/20 13:00', '2009/6/20 15:00', '2009/6/20 17:00', '2009/6/20 21:00', '2009/6/21 1:00', '2009/6/21 5:00', '2009/6/21 7:00', '2009/6/21 9:00', '2009/6/21 13:00', '2009/6/21 15:00', '2009/6/21 17:00', '2009/6/21 21:00', '2009/6/22 1:00', '2009/6/22 5:00', '2009/6/22 7:00', '2009/6/22 9:00', '2009/6/22 13:00', '2009/6/22 15:00', '2009/6/22 17:00', '2009/6/22 21:00', '2009/6/23 1:00', '2009/6/23 7:00', '2009/6/23 9:00', '2009/6/23 11:00', '2009/6/23 15:00', '2009/6/23 17:00', '2009/6/23 19:00', '2009/6/23 23:00', '2009/6/24 5:00', '2009/6/24 9:00', '2009/6/24 11:00', '2009/6/24 13:00', '2009/6/24 17:00', '2009/6/24 19:00', '2009/6/24 21:00', '2009/6/25 1:00', '2009/6/25 7:00', '2009/6/25 11:00', '2009/6/25 13:00', '2009/6/25 15:00', '2009/6/25 19:00', '2009/6/25 21:00', '2009/6/25 23:00', '2009/6/27 5:00', '2009/6/27 9:00', '2009/6/27 13:00', '2009/6/27 15:00', '2009/6/27 17:00', '2009/6/27 21:00', '2009/6/27 23:00', '2009/6/28 1:00', '2009/6/28 5:00', '2009/6/28 9:00', '2009/6/28 13:00', '2009/6/28 15:00', '2009/6/28 17:00', '2009/6/28 21:00', '2009/6/28 23:00', '2009/6/29 1:00', '2009/6/29 5:00', '2009/6/29 9:00', '2009/6/29 13:00', '2009/6/29 15:00', '2009/6/29 17:00', '2009/6/29 21:00', '2009/6/29 23:00', '2009/6/30 1:00', '2009/6/30 5:00', '2009/6/30 9:00', '2009/6/30 13:00', '2009/6/30 15:00', '2009/6/30 17:00', '2009/6/30 21:00', '2009/6/30 23:00', '2009/7/2 1:00', '2009/7/2 5:00', '2009/7/2 9:00', '2009/7/2 13:00', '2009/7/2 15:00', '2009/7/2 17:00', '2009/7/2 21:00', '2009/7/2 23:00', '2009/7/3 1:00', '2009/7/3 5:00', '2009/7/3 9:00', '2009/7/3 13:00', '2009/7/3 15:00', '2009/7/3 17:00', '2009/7/3 21:00', '2009/7/3 23:00', '2009/7/5 1:00', '2009/7/5 5:00', '2009/7/5 9:00', '2009/7/5 13:00', '2009/7/5 15:00', '2009/7/5 17:00', '2009/7/5 21:00', '2009/7/5 23:00', '2009/7/6 1:00', '2009/7/6 5:00', '2009/7/6 9:00', '2009/7/6 13:00', '2009/7/6 15:00', '2009/7/6 17:00', '2009/7/6 21:00', '2009/7/6 23:00', '2009/7/7 1:00', '2009/7/7 5:00', '2009/7/7 9:00', '2009/7/7 13:00', '2009/7/7 15:00', '2009/7/7 17:00', '2009/7/7 21:00', '2009/7/7 23:00', '2009/7/8 1:00', '2009/7/8 5:00', '2009/7/8 9:00', '2009/7/8 13:00', '2009/7/8 15:00', '2009/7/8 17:00', '2009/7/8 21:00', '2009/7/8 23:00', '2009/7/9 1:00', '2009/7/9 5:00', '2009/7/9 9:00', '2009/7/9 13:00', '2009/7/9 15:00', '2009/7/9 17:00', '2009/7/9 21:00', '2009/7/9 23:00', '2009/7/10 1:00', '2009/7/10 5:00', '2009/7/10 9:00', '2009/7/10 13:00', '2009/7/10 15:00', '2009/7/10 17:00', '2009/7/10 21:00', '2009/7/10 23:00', '2009/7/11 1:00', '2009/7/11 5:00', '2009/7/11 9:00', '2009/7/11 13:00', '2009/7/11 15:00', '2009/7/11 17:00', '2009/7/11 21:00', '2009/7/11 23:00', '2009/7/12 1:00', '2009/7/12 5:00', '2009/7/12 9:00', '2009/7/12 13:00', '2009/7/12 15:00', '2009/7/12 17:00', '2009/7/12 21:00', '2009/7/12 23:00', '2009/7/13 1:00', '2009/7/13 5:00', '2009/7/13 9:00', '2009/7/13 13:00', '2009/7/13 15:00', '2009/7/13 17:00', '2009/7/13 21:00', '2009/7/13 23:00', '2009/7/14 1:00', '2009/7/14 5:00', '2009/7/14 9:00', '2009/7/14 13:00', '2009/7/14 15:00', '2009/7/14 17:00', '2009/7/14 21:00', '2009/7/14 23:00', '2009/7/15 1:00', '2009/7/15 5:00', '2009/7/15 9:00', '2009/7/15 13:00', '2009/7/15 15:00', '2009/7/15 17:00', '2009/7/15 21:00', '2009/7/15 23:00', '2009/7/16 1:00', '2009/7/16 5:00', '2009/7/16 9:00', '2009/7/16 13:00', '2009/7/16 15:00', '2009/7/16 17:00', '2009/7/16 21:00', '2009/7/16 23:00', '2009/7/17 1:00', '2009/7/17 5:00', '2009/7/17 9:00', '2009/7/17 13:00', '2009/7/17 15:00', '2009/7/17 17:00', '2009/7/17 21:00', '2009/7/17 23:00', '2009/7/18 1:00', '2009/7/18 5:00', '2009/7/18 9:00', '2009/7/18 13:00', '2009/7/18 15:00', '2009/7/18 17:00', '2009/7/18 21:00', '2009/7/18 23:00', '2009/7/19 1:00', '2009/7/19 5:00', '2009/7/19 9:00', '2009/7/19 13:00', '2009/7/19 15:00', '2009/7/19 17:00', '2009/7/19 21:00', '2009/7/19 23:00', '2009/7/20 1:00', '2009/7/20 5:00', '2009/7/20 9:00', '2009/7/20 13:00', '2009/7/20 15:00', '2009/7/20 17:00', '2009/7/20 21:00', '2009/7/20 23:00', '2009/7/21 1:00', '2009/7/21 6:00', '2009/7/21 10:00', '2009/7/21 14:00', '2009/7/21 16:00', '2009/7/21 18:00', '2009/7/21 22:00', '2009/7/22 0:00', '2009/7/22 3:00', '2009/7/22 7:00', '2009/7/22 11:00', '2009/7/22 15:00', '2009/7/22 17:00', '2009/7/22 19:00', '2009/7/22 23:00', '2009/7/23 1:00', '2009/7/23 4:00', '2009/7/23 8:00', '2009/7/23 12:00', '2009/7/23 16:00', '2009/7/23 18:00', '2009/7/23 20:00', '2009/7/24 0:00', '2009/7/24 3:00', '2009/7/24 5:00', '2009/7/24 9:00', '2009/7/24 13:00', '2009/7/24 17:00', '2009/7/24 19:00', '2009/7/24 21:00', '2009/7/25 1:00', '2009/7/25 4:00', '2009/7/25 6:00', '2009/7/25 10:00', '2009/7/25 14:00', '2009/7/25 18:00', '2009/7/25 20:00', '2009/7/25 22:00', '2009/7/26 3:00', '2009/7/26 5:00', '2009/7/26 7:00', '2009/7/26 11:00', '2009/7/26 15:00', '2009/7/26 19:00', '2009/7/26 21:00', '2009/7/26 23:00', '2009/7/27 3:00', '2009/7/27 5:00', '2009/7/27 7:00', '2009/7/27 11:00', '2009/7/27 15:00', '2009/7/27 19:00', '2009/7/27 21:00', '2009/7/27 23:00', '2009/7/28 3:00', '2009/7/28 5:00', '2009/7/28 7:00', '2009/7/28 11:00', '2009/7/28 15:00', '2009/7/28 19:00', '2009/7/28 21:00', '2009/7/28 23:00', '2009/7/29 3:00', '2009/7/29 5:00', '2009/7/29 7:00', '2009/7/29 11:00', '2009/7/29 15:00', '2009/7/29 19:00', '2009/7/29 21:00', '2009/7/29 23:00', '2009/7/30 3:00', '2009/7/30 5:00', '2009/7/30 7:00', '2009/7/30 11:00', '2009/7/30 15:00', '2009/7/30 19:00', '2009/7/30 21:00', '2009/7/30 23:00', '2009/7/31 3:00', '2009/7/31 5:00', '2009/7/31 7:00', '2009/7/31 11:00', '2009/7/31 15:00', '2009/7/31 19:00', '2009/7/31 21:00', '2009/7/31 23:00', '2009/8/1 3:00', '2009/8/1 5:00', '2009/8/1 7:00', '2009/8/1 11:00', '2009/8/1 15:00', '2009/8/1 19:00', '2009/8/1 21:00', '2009/8/1 23:00', '2009/8/2 3:00', '2009/8/2 5:00', '2009/8/2 7:00', '2009/8/2 11:00', '2009/8/2 15:00', '2009/8/2 19:00', '2009/8/2 21:00', '2009/8/2 23:00', '2009/8/3 3:00', '2009/8/3 5:00', '2009/8/3 7:00', '2009/8/3 11:00', '2009/8/3 15:00', '2009/8/3 19:00', '2009/8/3 21:00', '2009/8/3 23:00', '2009/8/4 3:00', '2009/8/4 5:00', '2009/8/4 7:00', '2009/8/4 11:00', '2009/8/4 15:00', '2009/8/4 19:00', '2009/8/4 21:00', '2009/8/4 23:00', '2009/8/5 3:00', '2009/8/5 5:00', '2009/8/5 7:00', '2009/8/5 11:00', '2009/8/5 15:00', '2009/8/5 19:00', '2009/8/5 21:00', '2009/8/5 23:00', '2009/8/6 3:00', '2009/8/6 5:00', '2009/8/6 7:00', '2009/8/6 11:00', '2009/8/6 15:00', '2009/8/6 19:00', '2009/8/6 21:00', '2009/8/6 23:00', '2009/8/7 3:00', '2009/8/7 5:00', '2009/8/7 7:00', '2009/8/7 11:00', '2009/8/7 15:00', '2009/8/7 19:00', '2009/8/7 21:00', '2009/8/7 23:00', '2009/8/8 3:00', '2009/8/8 5:00', '2009/8/8 7:00', '2009/8/8 11:00', '2009/8/8 15:00', '2009/8/8 19:00', '2009/8/8 21:00', '2009/8/8 23:00', '2009/8/9 3:00', '2009/8/9 5:00', '2009/8/9 7:00', '2009/8/9 11:00', '2009/8/9 15:00', '2009/8/9 19:00', '2009/8/9 21:00', '2009/8/9 23:00', '2009/8/10 3:00', '2009/8/10 5:00', '2009/8/10 7:00', '2009/8/10 11:00', '2009/8/10 15:00', '2009/8/10 19:00', '2009/8/10 21:00', '2009/8/10 23:00', '2009/8/11 3:00', '2009/8/11 5:00', '2009/8/11 7:00', '2009/8/11 11:00', '2009/8/11 15:00', '2009/8/11 19:00', '2009/8/11 21:00', '2009/8/11 23:00', '2009/8/12 3:00', '2009/8/12 5:00', '2009/8/12 7:00', '2009/8/12 11:00', '2009/8/12 15:00', '2009/8/12 19:00', '2009/8/12 21:00', '2009/8/12 23:00', '2009/8/13 3:00', '2009/8/13 5:00', '2009/8/13 7:00', '2009/8/13 11:00', '2009/8/13 15:00', '2009/8/13 19:00', '2009/8/13 21:00', '2009/8/13 23:00', '2009/8/14 3:00', '2009/8/14 5:00', '2009/8/14 7:00', '2009/8/14 11:00', '2009/8/14 15:00', '2009/8/14 19:00', '2009/8/14 21:00', '2009/8/14 23:00', '2009/8/15 3:00', '2009/8/15 5:00', '2009/8/15 7:00', '2009/8/15 11:00', '2009/8/15 15:00', '2009/8/15 19:00', '2009/8/15 21:00', '2009/8/15 23:00', '2009/8/16 3:00', '2009/8/16 5:00', '2009/8/16 7:00', '2009/8/16 11:00', '2009/8/16 15:00', '2009/8/16 19:00', '2009/8/16 21:00', '2009/8/16 23:00', '2009/8/17 3:00', '2009/8/17 5:00', '2009/8/17 7:00', '2009/8/17 11:00', '2009/8/17 15:00', '2009/8/17 19:00', '2009/8/17 21:00', '2009/8/17 23:00', '2009/8/18 3:00', '2009/8/18 5:00', '2009/8/18 7:00', '2009/8/18 11:00', '2009/8/18 15:00', '2009/8/18 19:00', '2009/8/18 21:00', '2009/8/18 23:00', '2009/8/19 3:00', '2009/8/19 5:00', '2009/8/19 7:00', '2009/8/19 11:00', '2009/8/19 15:00', '2009/8/19 19:00', '2009/8/19 21:00', '2009/8/19 23:00', '2009/8/20 3:00', '2009/8/20 5:00', '2009/8/20 7:00', '2009/8/20 11:00', '2009/8/20 15:00', '2009/8/20 19:00', '2009/8/20 21:00', '2009/8/20 23:00', '2009/8/21 3:00', '2009/8/21 5:00', '2009/8/21 7:00', '2009/8/21 11:00', '2009/8/21 15:00', '2009/8/21 19:00', '2009/8/21 21:00', '2009/8/21 23:00', '2009/8/22 3:00', '2009/8/22 5:00', '2009/8/22 7:00', '2009/8/22 11:00', '2009/8/22 15:00', '2009/8/22 19:00', '2009/8/22 21:00', '2009/8/22 23:00', '2009/8/23 3:00', '2009/8/23 5:00', '2009/8/23 7:00', '2009/8/23 11:00', '2009/8/23 15:00', '2009/8/23 19:00', '2009/8/23 21:00', '2009/8/23 23:00', '2009/8/24 3:00', '2009/8/24 5:00', '2009/8/24 7:00', '2009/8/24 11:00', '2009/8/24 15:00', '2009/8/24 19:00', '2009/8/24 21:00', '2009/8/24 23:00', '2009/8/25 3:00', '2009/8/25 5:00', '2009/8/25 7:00', '2009/8/25 11:00', '2009/8/25 15:00', '2009/8/25 19:00', '2009/8/25 21:00', '2009/8/25 23:00', '2009/8/26 3:00', '2009/8/26 5:00', '2009/8/26 7:00', '2009/8/26 11:00', '2009/8/26 15:00', '2009/8/26 19:00', '2009/8/26 21:00', '2009/8/26 23:00', '2009/8/27 3:00', '2009/8/27 5:00', '2009/8/27 7:00', '2009/8/27 11:00', '2009/8/27 15:00', '2009/8/27 19:00', '2009/8/27 21:00', '2009/8/27 23:00', '2009/8/28 3:00', '2009/8/28 5:00', '2009/8/28 7:00', '2009/8/28 11:00', '2009/8/28 15:00', '2009/8/28 19:00', '2009/8/28 21:00', '2009/8/28 23:00', '2009/8/29 3:00', '2009/8/29 5:00', '2009/8/29 7:00', '2009/8/29 11:00', '2009/8/29 15:00', '2009/8/29 19:00', '2009/8/29 21:00', '2009/8/29 23:00', '2009/8/30 3:00', '2009/8/30 5:00', '2009/8/30 7:00', '2009/8/30 11:00', '2009/8/30 15:00', '2009/8/30 19:00', '2009/8/30 21:00', '2009/8/30 23:00', '2009/8/31 3:00', '2009/8/31 5:00', '2009/8/31 7:00', '2009/8/31 11:00', '2009/8/31 15:00', '2009/8/31 19:00', '2009/8/31 21:00', '2009/8/31 23:00', '2009/9/1 3:00', '2009/9/1 5:00', '2009/9/1 7:00', '2009/9/1 11:00', '2009/9/1 15:00', '2009/9/1 19:00', '2009/9/1 21:00', '2009/9/1 23:00', '2009/9/2 3:00', '2009/9/2 5:00', '2009/9/2 7:00', '2009/9/2 11:00', '2009/9/2 15:00', '2009/9/2 19:00', '2009/9/2 21:00', '2009/9/2 23:00', '2009/9/3 3:00', '2009/9/3 5:00', '2009/9/3 7:00', '2009/9/3 11:00', '2009/9/3 15:00', '2009/9/3 19:00', '2009/9/3 21:00', '2009/9/3 23:00', '2009/9/4 3:00', '2009/9/4 5:00', '2009/9/4 7:00', '2009/9/4 11:00', '2009/9/4 15:00', '2009/9/4 19:00', '2009/9/4 21:00', '2009/9/4 23:00', '2009/9/5 3:00', '2009/9/5 5:00', '2009/9/5 7:00', '2009/9/5 11:00', '2009/9/5 15:00', '2009/9/5 19:00', '2009/9/5 21:00', '2009/9/5 23:00', '2009/9/6 3:00', '2009/9/6 5:00', '2009/9/6 7:00', '2009/9/6 11:00', '2009/9/6 15:00', '2009/9/6 19:00', '2009/9/6 21:00', '2009/9/6 23:00', '2009/9/7 3:00', '2009/9/7 5:00', '2009/9/7 7:00', '2009/9/7 11:00', '2009/9/7 15:00', '2009/9/7 19:00', '2009/9/7 21:00', '2009/9/7 23:00', '2009/9/8 3:00', '2009/9/8 5:00', '2009/9/8 7:00', '2009/9/8 11:00', '2009/9/8 15:00', '2009/9/8 19:00', '2009/9/8 21:00', '2009/9/8 23:00', '2009/9/9 3:00', '2009/9/9 5:00', '2009/9/9 7:00', '2009/9/9 11:00', '2009/9/9 15:00', '2009/9/9 19:00', '2009/9/9 21:00', '2009/9/9 23:00', '2009/9/10 3:00', '2009/9/10 5:00', '2009/9/10 7:00', '2009/9/10 11:00', '2009/9/10 15:00', '2009/9/10 19:00', '2009/9/10 21:00', '2009/9/10 23:00', '2009/9/11 3:00', '2009/9/11 5:00', '2009/9/11 7:00', '2009/9/11 11:00', '2009/9/11 15:00', '2009/9/11 19:00', '2009/9/11 21:00', '2009/9/11 23:00', '2009/9/12 3:00', '2009/9/12 5:00', '2009/9/12 7:00', '2009/9/12 11:00', '2009/9/12 15:00', '2009/9/12 19:00', '2009/9/12 21:00', '2009/9/12 23:00', '2009/9/13 3:00', '2009/9/13 5:00', '2009/9/13 7:00', '2009/9/13 11:00', '2009/9/13 15:00', '2009/9/13 19:00', '2009/9/13 21:00', '2009/9/13 23:00', '2009/9/14 3:00', '2009/9/14 5:00', '2009/9/14 7:00', '2009/9/14 11:00', '2009/9/14 15:00', '2009/9/14 19:00', '2009/9/14 21:00', '2009/9/14 23:00', '2009/9/15 3:00', '2009/9/15 5:00', '2009/9/15 7:00', '2009/9/15 11:00', '2009/9/15 15:00', '2009/9/15 19:00', '2009/9/15 21:00', '2009/9/15 23:00', '2009/9/16 3:00', '2009/9/16 5:00', '2009/9/16 7:00', '2009/9/16 11:00', '2009/9/16 15:00', '2009/9/16 19:00', '2009/9/16 21:00', '2009/9/16 23:00', '2009/9/17 3:00', '2009/9/17 5:00', '2009/9/17 7:00', '2009/9/17 11:00', '2009/9/17 15:00', '2009/9/17 19:00', '2009/9/17 21:00', '2009/9/17 23:00', '2009/9/18 3:00', '2009/9/18 5:00', '2009/9/18 7:00', '2009/9/18 11:00', '2009/9/18 15:00', '2009/9/18 19:00', '2009/9/18 21:00', '2009/9/18 23:00', '2009/9/19 3:00', '2009/9/19 5:00', '2009/9/19 7:00', '2009/9/19 11:00', '2009/9/19 15:00', '2009/9/19 19:00', '2009/9/19 21:00', '2009/9/19 23:00', '2009/9/20 3:00', '2009/9/20 5:00', '2009/9/20 7:00', '2009/9/20 11:00', '2009/9/20 15:00', '2009/9/20 19:00', '2009/9/20 21:00', '2009/9/20 23:00', '2009/9/21 3:00', '2009/9/21 5:00', '2009/9/21 7:00', '2009/9/21 11:00', '2009/9/21 15:00', '2009/9/21 19:00', '2009/9/21 21:00', '2009/9/21 23:00', '2009/9/22 3:00', '2009/9/22 5:00', '2009/9/22 7:00', '2009/9/22 11:00', '2009/9/22 15:00', '2009/9/22 19:00', '2009/9/22 21:00', '2009/9/22 23:00', '2009/9/23 3:00', '2009/9/23 5:00', '2009/9/23 7:00', '2009/9/23 11:00', '2009/9/23 15:00', '2009/9/23 19:00', '2009/9/23 21:00', '2009/9/23 23:00', '2009/9/24 3:00', '2009/9/24 5:00', '2009/9/24 7:00', '2009/9/24 11:00', '2009/9/24 15:00', '2009/9/24 19:00', '2009/9/24 21:00', '2009/9/24 23:00', '2009/9/25 3:00', '2009/9/25 5:00', '2009/9/25 7:00', '2009/9/25 11:00', '2009/9/25 15:00', '2009/9/25 19:00', '2009/9/25 21:00', '2009/9/25 23:00', '2009/9/26 3:00', '2009/9/26 5:00', '2009/9/26 7:00', '2009/9/26 11:00', '2009/9/26 15:00', '2009/9/26 19:00', '2009/9/26 21:00', '2009/9/26 23:00', '2009/9/27 3:00', '2009/9/27 5:00', '2009/9/27 7:00', '2009/9/27 11:00', '2009/9/27 15:00', '2009/9/27 19:00', '2009/9/27 21:00', '2009/9/27 23:00', '2009/9/28 3:00', '2009/9/28 5:00', '2009/9/28 7:00', '2009/9/28 11:00', '2009/9/28 15:00', '2009/9/28 19:00', '2009/9/28 21:00', '2009/9/28 23:00', '2009/9/29 3:00', '2009/9/29 5:00', '2009/9/29 7:00', '2009/9/29 11:00', '2009/9/29 15:00', '2009/9/29 19:00', '2009/9/29 21:00', '2009/9/29 23:00', '2009/9/30 3:00', '2009/9/30 5:00', '2009/9/30 7:00', '2009/9/30 11:00', '2009/9/30 15:00', '2009/9/30 19:00', '2009/9/30 21:00', '2009/9/30 23:00', '2009/10/1 3:00', '2009/10/1 5:00', '2009/10/1 7:00', '2009/10/1 11:00', '2009/10/1 15:00', '2009/10/1 19:00', '2009/10/1 21:00', '2009/10/1 23:00', '2009/10/2 3:00', '2009/10/2 5:00', '2009/10/2 7:00', '2009/10/2 11:00', '2009/10/2 15:00', '2009/10/2 19:00', '2009/10/2 21:00', '2009/10/2 23:00', '2009/10/3 3:00', '2009/10/3 5:00', '2009/10/3 7:00', '2009/10/3 11:00', '2009/10/3 15:00', '2009/10/3 19:00', '2009/10/3 21:00', '2009/10/3 23:00', '2009/10/4 3:00', '2009/10/4 5:00', '2009/10/4 7:00', '2009/10/4 11:00', '2009/10/4 15:00', '2009/10/4 19:00', '2009/10/4 21:00', '2009/10/4 23:00', '2009/10/5 3:00', '2009/10/5 5:00', '2009/10/5 7:00', '2009/10/5 11:00', '2009/10/5 15:00', '2009/10/5 19:00', '2009/10/5 21:00', '2009/10/5 23:00', '2009/10/6 3:00', '2009/10/6 5:00', '2009/10/6 7:00', '2009/10/6 11:00', '2009/10/6 15:00', '2009/10/6 19:00', '2009/10/6 21:00', '2009/10/6 23:00', '2009/10/7 3:00', '2009/10/7 5:00', '2009/10/7 7:00', '2009/10/7 11:00', '2009/10/7 15:00', '2009/10/7 19:00', '2009/10/7 21:00', '2009/10/7 23:00', '2009/10/8 3:00', '2009/10/8 5:00', '2009/10/8 7:00', '2009/10/8 11:00', '2009/10/8 15:00', '2009/10/8 19:00', '2009/10/8 21:00', '2009/10/8 23:00', '2009/10/9 3:00', '2009/10/9 5:00', '2009/10/9 7:00', '2009/10/9 11:00', '2009/10/9 15:00', '2009/10/9 19:00', '2009/10/9 21:00', '2009/10/9 23:00', '2009/10/10 3:00', '2009/10/10 5:00', '2009/10/10 7:00', '2009/10/10 11:00', '2009/10/10 15:00', '2009/10/10 19:00', '2009/10/10 21:00', '2009/10/10 23:00', '2009/10/11 3:00', '2009/10/11 5:00', '2009/10/11 7:00', '2009/10/11 11:00', '2009/10/11 15:00', '2009/10/11 19:00', '2009/10/11 21:00', '2009/10/11 23:00', '2009/10/12 3:00', '2009/10/12 5:00', '2009/10/12 7:00', '2009/10/12 11:00', '2009/10/12 15:00', '2009/10/12 19:00', '2009/10/12 21:00', '2009/10/12 23:00', '2009/10/13 3:00', '2009/10/13 5:00', '2009/10/13 7:00', '2009/10/13 11:00', '2009/10/13 15:00', '2009/10/13 19:00', '2009/10/13 21:00', '2009/10/13 23:00', '2009/10/14 3:00', '2009/10/14 5:00', '2009/10/14 7:00', '2009/10/14 11:00', '2009/10/14 15:00', '2009/10/14 19:00', '2009/10/14 21:00', '2009/10/14 23:00', '2009/10/15 3:00', '2009/10/15 5:00', '2009/10/15 7:00', '2009/10/15 11:00', '2009/10/15 15:00', '2009/10/15 19:00', '2009/10/15 21:00', '2009/10/15 23:00', '2009/10/16 3:00', '2009/10/16 5:00', '2009/10/16 7:00', '2009/10/16 11:00', '2009/10/16 15:00', '2009/10/16 19:00', '2009/10/16 21:00', '2009/10/16 23:00', '2009/10/17 3:00', '2009/10/17 5:00', '2009/10/17 7:00', '2009/10/17 11:00', '2009/10/17 15:00', '2009/10/17 19:00', '2009/10/17 21:00', '2009/10/17 23:00', '2009/10/18 3:00', '2009/10/18 5:00', '2009/10/18 7:00']
import pandas as pd
df = pd.DataFrame({'Timestamp': timeData})
df["Timestamp"] = pd.to_datetime(df["Timestamp"], format="%Y/%m/%d %H:%M")
df['hours'] = df["Timestamp"].dt.strftime('%I%p').str.lower().str.lstrip('0')
df['days'] = df["Timestamp"].dt.day_name()
df = pd.crosstab(df['days'], df['hours']).reindex(index=df['days'].unique(), columns=df['hours'].unique())
df
hours 5am 7am 9am 1pm 3pm 5pm 9pm 1am 11am 7pm 11pm 6am 10am 2pm 4pm 6pm 10pm 12am 3am 4am 8am 12pm 8pm
days
Friday 18 14 6 6 17 6 18 4 12 13 15 0 0 0 0 0 0 1 13 0 0 0 0
Saturday 17 14 5 5 17 5 17 5 12 12 15 1 1 1 0 1 1 0 12 1 0 0 1
Sunday 19 15 6 6 18 6 18 6 12 12 16 0 0 0 0 0 0 0 13 0 0 0 0
Monday 18 14 6 6 18 6 18 6 12 12 16 0 0 0 0 0 0 0 12 0 0 0 0
Tuesday 16 14 5 4 17 5 16 6 13 13 16 1 1 1 1 1 1 0 12 0 0 0 0
Wednesday 16 14 4 4 16 5 16 3 14 14 15 0 0 0 0 0 0 1 13 0 0 0 0
Thursday 16 14 4 5 17 4 17 6 13 13 16 0 0 0 1 1 0 0 12 1 1 1 1
这里是一个使用 plotly 的方法的例子。数据被转换为长格式,并通过为 x 轴和 y 轴创建显示顺序列表来绘制图形。如果要限制时间轴,可以把原始数据提取到你需要的时间段再画出来。
df_long = df.groupby(['days','hours']).count()
df_long.reset_index(inplace=True)
df_long.head()
days hours Timestamp
0 Friday 11am 12
1 Friday 11pm 15
2 Friday 12am 1
3 Friday 1am 4
4 Friday 1pm 6
import plotly.express as px
order = {'hours':['5am', '6am', '7am', '8am', '9am', '10am', '11am', '12am',
'1pm', '2pm', '3pm', '4pm', '5pm', '6pm', '7pm', '8pm', '9pm', '10pm', '11pm', '12pm',
'1am', '2am', '3am', '4am']}
week_order = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
fig = px.scatter(df_long,
x='hours',
y='days',
size='Timestamp',
color='days',
category_orders=order)
fig.update_yaxes(categoryarray=week_order)
fig.show()
牵牛星
还有另一个图形库,Altair. It has the advantage that the data can be used directly with pandas. See this page。
import altair as alt
from vega_datasets import data
df['count'] = 1
df['Timestamp'] = pd.to_datetime(df['Timestamp'])
alt.Chart(df).mark_circle().encode(
x='hours(Timestamp):O',
y='day(Timestamp):O',
size='sum(count):Q'
)
Python、Numpy 和 Matplotlib
数据排序后,简单画7个散点图,
注意关闭所有不需要的视觉元素(左,
顶部、右侧书脊和 y 刻度和刻度标签)。
简单说一下使用默认的属性周期是强制的
在轴之间共享,因此每个轴的颜色都不同。
import numpy as np
import matplotlib.pyplot as plt
# Some constants that will be useful later (I find writing list of strings
# boring and error prone, I prefer to split a string of space separated items)
AMPM_TO_24 = dict(
zip('12a 1a 2a 3a 4a 5a 6a 7a 8a 9a 10a 11a 12p 1p 2p 3p 4p 5p 6p 7p 8p 9p 10p 11p'.split(),
'0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23'.split()))
DAYS_OW = 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'.split()
# I have slightly edited your data: ① shortened am/mp ② used commas
data = '''\
hour, 5a,7a,9a,1p,3p,5p,9p,1a,11a,7p,11p,6a,10a,2p,4p,6p,10p,12a,3a,4a,8a,12p,8p
Friday, 18,14, 6, 6,17, 6,18, 4, 12,13, 15, 0, 0, 0, 0, 0, 0, 1,13, 0, 0, 0, 0
Saturday, 17,14, 5, 5,17, 5,17, 5, 12,12, 15, 1, 1, 1, 0, 1, 1, 0,12, 1, 0, 0, 1
Sunday, 19,15, 6, 6,18, 6,18, 6, 12,12, 16, 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 0
Monday, 18,14, 6, 6,18, 6,18, 6, 12,12, 16, 0, 0, 0, 0, 0, 0, 0,12, 0, 0, 0, 0
Tuesday, 16,14, 5, 4,17, 5,16, 6, 13,13, 16, 1, 1, 1, 1, 1, 1, 0,12, 0, 0, 0, 0
Wednesday,16,14, 4, 4,16, 5,16, 3, 14,14, 15, 0, 0, 0, 0, 0, 0, 1,13, 0, 0, 0, 0
Thursday, 16,14, 4, 5,17, 4,17, 6, 13,13, 16, 0, 0, 0, 1, 1, 0, 0,12, 1, 1, 1, 1'''.split('\n')
# ① extract hours from 1st line, ② convert to 0÷24 and place in a Numpy array
_, *hours = (h.strip() for h in data[0].split(','))
hours = np.array([AMPM_TO_24[h] for h in hours], dtype=int)
zero = np.zeros_like(hours)
# ① generator of list of items, ② convert data to dict, its values are Numpy arrays
csv = (line.split(',') for line in data[1:])
data = {dow:np.array(values, dtype=int) for dow, *values in csv}
################### PLOTTING STARTS HERE ################
# sharey=all because I want the same scale for all the circles
fig, axes = plt.subplots(7, figsize=(9, 6),
sharey='all', constrained_layout=1)
# prop_cycle is renewed for each Axes, we want a single instance for the figure
fig_prop_cycle = plt.rcParams['axes.prop_cycle']()
for ax, dow in zip(axes, DAYS_OW[::-1]):
#or ax, dow in zip(axes, data): # alternative order of plots
ax.scatter(hours, [0 for _ in hours], 4*data[dow]**2, **next(fig_prop_cycle), alpha=0.6)
for x in 'left top right'.split():ax.spines[x].set_visible(False)
ax.set_xticks(range(0,24,3)) ; ax.set_xlim((-1, 25))
ax.set_xticks(range(25), minor=True)
ax.set_yticks([]) ; ax.set_yticklabels([])
ax.set_ylabel(dow, rotation=0, ha='right', va='center', fontsize=12, fontweight='bold')
plt.show()
关于以前的版本,我没有意识到对 values
和
后来对 hours
进行排序是一种空操作(请参阅编辑历史记录)。
回复:日期的排序。
我觉得这种类型的图表读起来就像一页文字,
从上到下,与常见的情节相反
纵坐标是从下到上排列的,因此我的想法是,
在此答案的先前修订版中提出,
其中星期几按以下顺序显示
它们在周五到周四的数据中被发现。
- 更新:为什么是黑色/灰色配色方案。我在暗模式下看 SO。样本图必须是透明的,所以它看起来是黑色/灰色。当我查看 phone 上的问题时,我才意识到情况并非如此,该问题未设置为使用 SO 暗模式。需要更改的内容在代码中很明显,我没有时间更改答案。
- 使用
seaborn.scatterplot
- 使用
sizes=(50, 1000)
调整气泡大小。 0
的大小为 50
,最大值的大小为 1000
。将 50
更改为 0
以获得 0
大小 0
值。
- 使用您的示例数据框
df
,到 .crosstab
之前的点
hours
应该在索引上,因为索引成为 x 轴
- 按照代码中的注释设置变量轴和图形参数,以生成所需的图
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# beginning with your dataframe before doing the crosstab, create the crosstab as follows
ct = pd.crosstab(df.hours, df.days)
# the data is missing anything for 2am add that to ct as 0s
missing = pd.DataFrame({'Friday': [0], 'Monday': [0], 'Saturday': [0], 'Sunday': [0], 'Thursday': [0], 'Tuesday': [0], 'Wednesday': [0]}, index=['2am'])
ct = ct.append(missing)
# sorted column and axis values
hours = ['5am', '6am', '7am', '8am', '9am', '10am', '11am', '12am', '1pm', '2pm', '3pm', '4pm', '5pm', '6pm', '7pm', '8pm', '9pm', '10pm', '11pm', '12pm', '1am', '2am', '3am', '4am']
days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
# colors for plots
colors = ['purple', 'lime', 'yellow', 'red', 'blue', 'green', 'orange']
# reorder the index and columns
ct = ct.loc[hours, days]
# create the figure
fig, axes = plt.subplots(nrows=7, figsize=(14, 7), facecolor='black', constrained_layout=1)
# iterate through days, axes, and colors
for col, ax, color in zip(days, axes, colors):
# select data
data = ct[col].reset_index()
# plot
sns.scatterplot(data=data, x='index', y=[0]*len(data), size=col, ax=ax, color=color, legend=False, ec='none', sizes=(50, 1000), palette='muted', alpha=0.5)
# Hide the right and top spines
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
# set the y-tick name
ax.set_yticks([0])
ax.set_yticklabels([col])
# remove the x-axis label
ax.set_xlabel('')
# set the x margin
ax.margins(x=0.02)
# set the plot facecolor
ax.set_facecolor('black')
# set axis labels, ticklabels and tick colors
ax.tick_params(colors='gray', which='both')
# set spine color
ax.spines['bottom'].set(color='gray')
display(ct)
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
5am 19 18 16 16 16 18 17
6am 0 0 1 0 0 0 1
7am 15 14 14 14 14 14 14
8am 0 0 0 0 1 0 0
9am 6 6 5 4 4 6 5
10am 0 0 1 0 0 0 1
11am 12 12 13 14 13 12 12
12am 0 0 0 1 0 1 0
1pm 6 6 4 4 5 6 5
2pm 0 0 1 0 0 0 1
3pm 18 18 17 16 17 17 17
4pm 0 0 1 0 1 0 0
5pm 6 6 5 5 4 6 5
6pm 0 0 1 0 1 0 1
7pm 12 12 13 14 13 13 12
8pm 0 0 0 0 1 0 1
9pm 18 18 16 16 17 18 17
10pm 0 0 1 0 0 0 1
11pm 16 16 16 15 16 15 15
12pm 0 0 0 0 1 0 0
1am 6 6 6 3 6 4 5
2am 0 0 0 0 0 0 0
3am 13 12 12 13 12 13 12
4am 0 0 0 0 1 0 1
我只是想知道是否有任何 python 包可用于在单个轴上绘制散点图。我乐于接受新的想法和方法,并希望在开始之前试探一下
是否可以用 Python 绘制上面的图如果是,将使用哪个包来绘制上面的图?有人可以阐明用 Python 绘制上述图吗?我很乐意收到您的任何线索。
示例集:
timeData = ['2009/6/12 5:00', '2009/6/12 7:00', '2009/6/12 9:00', '2009/6/12 13:00', '2009/6/12 15:00', '2009/6/12 17:00', '2009/6/12 21:00', '2009/6/13 1:00', '2009/6/13 5:00', '2009/6/13 7:00', '2009/6/13 9:00', '2009/6/13 13:00', '2009/6/13 15:00', '2009/6/13 17:00', '2009/6/13 21:00', '2009/6/14 1:00', '2009/6/14 5:00', '2009/6/14 7:00', '2009/6/14 9:00', '2009/6/14 13:00', '2009/6/14 15:00', '2009/6/14 17:00', '2009/6/14 21:00', '2009/6/15 1:00', '2009/6/15 5:00', '2009/6/15 7:00', '2009/6/15 9:00', '2009/6/15 13:00', '2009/6/15 15:00', '2009/6/15 17:00', '2009/6/15 21:00', '2009/6/16 1:00', '2009/6/16 5:00', '2009/6/16 7:00', '2009/6/16 9:00', '2009/6/16 13:00', '2009/6/16 15:00', '2009/6/16 17:00', '2009/6/16 21:00', '2009/6/17 1:00', '2009/6/17 5:00', '2009/6/17 7:00', '2009/6/17 9:00', '2009/6/17 13:00', '2009/6/17 15:00', '2009/6/17 17:00', '2009/6/17 21:00', '2009/6/18 1:00', '2009/6/18 5:00', '2009/6/18 7:00', '2009/6/18 9:00', '2009/6/18 13:00', '2009/6/18 15:00', '2009/6/18 17:00', '2009/6/18 21:00', '2009/6/19 1:00', '2009/6/19 5:00', '2009/6/19 7:00', '2009/6/19 9:00', '2009/6/19 13:00', '2009/6/19 15:00', '2009/6/19 17:00', '2009/6/19 21:00', '2009/6/20 1:00', '2009/6/20 5:00', '2009/6/20 7:00', '2009/6/20 9:00', '2009/6/20 13:00', '2009/6/20 15:00', '2009/6/20 17:00', '2009/6/20 21:00', '2009/6/21 1:00', '2009/6/21 5:00', '2009/6/21 7:00', '2009/6/21 9:00', '2009/6/21 13:00', '2009/6/21 15:00', '2009/6/21 17:00', '2009/6/21 21:00', '2009/6/22 1:00', '2009/6/22 5:00', '2009/6/22 7:00', '2009/6/22 9:00', '2009/6/22 13:00', '2009/6/22 15:00', '2009/6/22 17:00', '2009/6/22 21:00', '2009/6/23 1:00', '2009/6/23 7:00', '2009/6/23 9:00', '2009/6/23 11:00', '2009/6/23 15:00', '2009/6/23 17:00', '2009/6/23 19:00', '2009/6/23 23:00', '2009/6/24 5:00', '2009/6/24 9:00', '2009/6/24 11:00', '2009/6/24 13:00', '2009/6/24 17:00', '2009/6/24 19:00', '2009/6/24 21:00', '2009/6/25 1:00', '2009/6/25 7:00', '2009/6/25 11:00', '2009/6/25 13:00', '2009/6/25 15:00', '2009/6/25 19:00', '2009/6/25 21:00', '2009/6/25 23:00', '2009/6/27 5:00', '2009/6/27 9:00', '2009/6/27 13:00', '2009/6/27 15:00', '2009/6/27 17:00', '2009/6/27 21:00', '2009/6/27 23:00', '2009/6/28 1:00', '2009/6/28 5:00', '2009/6/28 9:00', '2009/6/28 13:00', '2009/6/28 15:00', '2009/6/28 17:00', '2009/6/28 21:00', '2009/6/28 23:00', '2009/6/29 1:00', '2009/6/29 5:00', '2009/6/29 9:00', '2009/6/29 13:00', '2009/6/29 15:00', '2009/6/29 17:00', '2009/6/29 21:00', '2009/6/29 23:00', '2009/6/30 1:00', '2009/6/30 5:00', '2009/6/30 9:00', '2009/6/30 13:00', '2009/6/30 15:00', '2009/6/30 17:00', '2009/6/30 21:00', '2009/6/30 23:00', '2009/7/2 1:00', '2009/7/2 5:00', '2009/7/2 9:00', '2009/7/2 13:00', '2009/7/2 15:00', '2009/7/2 17:00', '2009/7/2 21:00', '2009/7/2 23:00', '2009/7/3 1:00', '2009/7/3 5:00', '2009/7/3 9:00', '2009/7/3 13:00', '2009/7/3 15:00', '2009/7/3 17:00', '2009/7/3 21:00', '2009/7/3 23:00', '2009/7/5 1:00', '2009/7/5 5:00', '2009/7/5 9:00', '2009/7/5 13:00', '2009/7/5 15:00', '2009/7/5 17:00', '2009/7/5 21:00', '2009/7/5 23:00', '2009/7/6 1:00', '2009/7/6 5:00', '2009/7/6 9:00', '2009/7/6 13:00', '2009/7/6 15:00', '2009/7/6 17:00', '2009/7/6 21:00', '2009/7/6 23:00', '2009/7/7 1:00', '2009/7/7 5:00', '2009/7/7 9:00', '2009/7/7 13:00', '2009/7/7 15:00', '2009/7/7 17:00', '2009/7/7 21:00', '2009/7/7 23:00', '2009/7/8 1:00', '2009/7/8 5:00', '2009/7/8 9:00', '2009/7/8 13:00', '2009/7/8 15:00', '2009/7/8 17:00', '2009/7/8 21:00', '2009/7/8 23:00', '2009/7/9 1:00', '2009/7/9 5:00', '2009/7/9 9:00', '2009/7/9 13:00', '2009/7/9 15:00', '2009/7/9 17:00', '2009/7/9 21:00', '2009/7/9 23:00', '2009/7/10 1:00', '2009/7/10 5:00', '2009/7/10 9:00', '2009/7/10 13:00', '2009/7/10 15:00', '2009/7/10 17:00', '2009/7/10 21:00', '2009/7/10 23:00', '2009/7/11 1:00', '2009/7/11 5:00', '2009/7/11 9:00', '2009/7/11 13:00', '2009/7/11 15:00', '2009/7/11 17:00', '2009/7/11 21:00', '2009/7/11 23:00', '2009/7/12 1:00', '2009/7/12 5:00', '2009/7/12 9:00', '2009/7/12 13:00', '2009/7/12 15:00', '2009/7/12 17:00', '2009/7/12 21:00', '2009/7/12 23:00', '2009/7/13 1:00', '2009/7/13 5:00', '2009/7/13 9:00', '2009/7/13 13:00', '2009/7/13 15:00', '2009/7/13 17:00', '2009/7/13 21:00', '2009/7/13 23:00', '2009/7/14 1:00', '2009/7/14 5:00', '2009/7/14 9:00', '2009/7/14 13:00', '2009/7/14 15:00', '2009/7/14 17:00', '2009/7/14 21:00', '2009/7/14 23:00', '2009/7/15 1:00', '2009/7/15 5:00', '2009/7/15 9:00', '2009/7/15 13:00', '2009/7/15 15:00', '2009/7/15 17:00', '2009/7/15 21:00', '2009/7/15 23:00', '2009/7/16 1:00', '2009/7/16 5:00', '2009/7/16 9:00', '2009/7/16 13:00', '2009/7/16 15:00', '2009/7/16 17:00', '2009/7/16 21:00', '2009/7/16 23:00', '2009/7/17 1:00', '2009/7/17 5:00', '2009/7/17 9:00', '2009/7/17 13:00', '2009/7/17 15:00', '2009/7/17 17:00', '2009/7/17 21:00', '2009/7/17 23:00', '2009/7/18 1:00', '2009/7/18 5:00', '2009/7/18 9:00', '2009/7/18 13:00', '2009/7/18 15:00', '2009/7/18 17:00', '2009/7/18 21:00', '2009/7/18 23:00', '2009/7/19 1:00', '2009/7/19 5:00', '2009/7/19 9:00', '2009/7/19 13:00', '2009/7/19 15:00', '2009/7/19 17:00', '2009/7/19 21:00', '2009/7/19 23:00', '2009/7/20 1:00', '2009/7/20 5:00', '2009/7/20 9:00', '2009/7/20 13:00', '2009/7/20 15:00', '2009/7/20 17:00', '2009/7/20 21:00', '2009/7/20 23:00', '2009/7/21 1:00', '2009/7/21 6:00', '2009/7/21 10:00', '2009/7/21 14:00', '2009/7/21 16:00', '2009/7/21 18:00', '2009/7/21 22:00', '2009/7/22 0:00', '2009/7/22 3:00', '2009/7/22 7:00', '2009/7/22 11:00', '2009/7/22 15:00', '2009/7/22 17:00', '2009/7/22 19:00', '2009/7/22 23:00', '2009/7/23 1:00', '2009/7/23 4:00', '2009/7/23 8:00', '2009/7/23 12:00', '2009/7/23 16:00', '2009/7/23 18:00', '2009/7/23 20:00', '2009/7/24 0:00', '2009/7/24 3:00', '2009/7/24 5:00', '2009/7/24 9:00', '2009/7/24 13:00', '2009/7/24 17:00', '2009/7/24 19:00', '2009/7/24 21:00', '2009/7/25 1:00', '2009/7/25 4:00', '2009/7/25 6:00', '2009/7/25 10:00', '2009/7/25 14:00', '2009/7/25 18:00', '2009/7/25 20:00', '2009/7/25 22:00', '2009/7/26 3:00', '2009/7/26 5:00', '2009/7/26 7:00', '2009/7/26 11:00', '2009/7/26 15:00', '2009/7/26 19:00', '2009/7/26 21:00', '2009/7/26 23:00', '2009/7/27 3:00', '2009/7/27 5:00', '2009/7/27 7:00', '2009/7/27 11:00', '2009/7/27 15:00', '2009/7/27 19:00', '2009/7/27 21:00', '2009/7/27 23:00', '2009/7/28 3:00', '2009/7/28 5:00', '2009/7/28 7:00', '2009/7/28 11:00', '2009/7/28 15:00', '2009/7/28 19:00', '2009/7/28 21:00', '2009/7/28 23:00', '2009/7/29 3:00', '2009/7/29 5:00', '2009/7/29 7:00', '2009/7/29 11:00', '2009/7/29 15:00', '2009/7/29 19:00', '2009/7/29 21:00', '2009/7/29 23:00', '2009/7/30 3:00', '2009/7/30 5:00', '2009/7/30 7:00', '2009/7/30 11:00', '2009/7/30 15:00', '2009/7/30 19:00', '2009/7/30 21:00', '2009/7/30 23:00', '2009/7/31 3:00', '2009/7/31 5:00', '2009/7/31 7:00', '2009/7/31 11:00', '2009/7/31 15:00', '2009/7/31 19:00', '2009/7/31 21:00', '2009/7/31 23:00', '2009/8/1 3:00', '2009/8/1 5:00', '2009/8/1 7:00', '2009/8/1 11:00', '2009/8/1 15:00', '2009/8/1 19:00', '2009/8/1 21:00', '2009/8/1 23:00', '2009/8/2 3:00', '2009/8/2 5:00', '2009/8/2 7:00', '2009/8/2 11:00', '2009/8/2 15:00', '2009/8/2 19:00', '2009/8/2 21:00', '2009/8/2 23:00', '2009/8/3 3:00', '2009/8/3 5:00', '2009/8/3 7:00', '2009/8/3 11:00', '2009/8/3 15:00', '2009/8/3 19:00', '2009/8/3 21:00', '2009/8/3 23:00', '2009/8/4 3:00', '2009/8/4 5:00', '2009/8/4 7:00', '2009/8/4 11:00', '2009/8/4 15:00', '2009/8/4 19:00', '2009/8/4 21:00', '2009/8/4 23:00', '2009/8/5 3:00', '2009/8/5 5:00', '2009/8/5 7:00', '2009/8/5 11:00', '2009/8/5 15:00', '2009/8/5 19:00', '2009/8/5 21:00', '2009/8/5 23:00', '2009/8/6 3:00', '2009/8/6 5:00', '2009/8/6 7:00', '2009/8/6 11:00', '2009/8/6 15:00', '2009/8/6 19:00', '2009/8/6 21:00', '2009/8/6 23:00', '2009/8/7 3:00', '2009/8/7 5:00', '2009/8/7 7:00', '2009/8/7 11:00', '2009/8/7 15:00', '2009/8/7 19:00', '2009/8/7 21:00', '2009/8/7 23:00', '2009/8/8 3:00', '2009/8/8 5:00', '2009/8/8 7:00', '2009/8/8 11:00', '2009/8/8 15:00', '2009/8/8 19:00', '2009/8/8 21:00', '2009/8/8 23:00', '2009/8/9 3:00', '2009/8/9 5:00', '2009/8/9 7:00', '2009/8/9 11:00', '2009/8/9 15:00', '2009/8/9 19:00', '2009/8/9 21:00', '2009/8/9 23:00', '2009/8/10 3:00', '2009/8/10 5:00', '2009/8/10 7:00', '2009/8/10 11:00', '2009/8/10 15:00', '2009/8/10 19:00', '2009/8/10 21:00', '2009/8/10 23:00', '2009/8/11 3:00', '2009/8/11 5:00', '2009/8/11 7:00', '2009/8/11 11:00', '2009/8/11 15:00', '2009/8/11 19:00', '2009/8/11 21:00', '2009/8/11 23:00', '2009/8/12 3:00', '2009/8/12 5:00', '2009/8/12 7:00', '2009/8/12 11:00', '2009/8/12 15:00', '2009/8/12 19:00', '2009/8/12 21:00', '2009/8/12 23:00', '2009/8/13 3:00', '2009/8/13 5:00', '2009/8/13 7:00', '2009/8/13 11:00', '2009/8/13 15:00', '2009/8/13 19:00', '2009/8/13 21:00', '2009/8/13 23:00', '2009/8/14 3:00', '2009/8/14 5:00', '2009/8/14 7:00', '2009/8/14 11:00', '2009/8/14 15:00', '2009/8/14 19:00', '2009/8/14 21:00', '2009/8/14 23:00', '2009/8/15 3:00', '2009/8/15 5:00', '2009/8/15 7:00', '2009/8/15 11:00', '2009/8/15 15:00', '2009/8/15 19:00', '2009/8/15 21:00', '2009/8/15 23:00', '2009/8/16 3:00', '2009/8/16 5:00', '2009/8/16 7:00', '2009/8/16 11:00', '2009/8/16 15:00', '2009/8/16 19:00', '2009/8/16 21:00', '2009/8/16 23:00', '2009/8/17 3:00', '2009/8/17 5:00', '2009/8/17 7:00', '2009/8/17 11:00', '2009/8/17 15:00', '2009/8/17 19:00', '2009/8/17 21:00', '2009/8/17 23:00', '2009/8/18 3:00', '2009/8/18 5:00', '2009/8/18 7:00', '2009/8/18 11:00', '2009/8/18 15:00', '2009/8/18 19:00', '2009/8/18 21:00', '2009/8/18 23:00', '2009/8/19 3:00', '2009/8/19 5:00', '2009/8/19 7:00', '2009/8/19 11:00', '2009/8/19 15:00', '2009/8/19 19:00', '2009/8/19 21:00', '2009/8/19 23:00', '2009/8/20 3:00', '2009/8/20 5:00', '2009/8/20 7:00', '2009/8/20 11:00', '2009/8/20 15:00', '2009/8/20 19:00', '2009/8/20 21:00', '2009/8/20 23:00', '2009/8/21 3:00', '2009/8/21 5:00', '2009/8/21 7:00', '2009/8/21 11:00', '2009/8/21 15:00', '2009/8/21 19:00', '2009/8/21 21:00', '2009/8/21 23:00', '2009/8/22 3:00', '2009/8/22 5:00', '2009/8/22 7:00', '2009/8/22 11:00', '2009/8/22 15:00', '2009/8/22 19:00', '2009/8/22 21:00', '2009/8/22 23:00', '2009/8/23 3:00', '2009/8/23 5:00', '2009/8/23 7:00', '2009/8/23 11:00', '2009/8/23 15:00', '2009/8/23 19:00', '2009/8/23 21:00', '2009/8/23 23:00', '2009/8/24 3:00', '2009/8/24 5:00', '2009/8/24 7:00', '2009/8/24 11:00', '2009/8/24 15:00', '2009/8/24 19:00', '2009/8/24 21:00', '2009/8/24 23:00', '2009/8/25 3:00', '2009/8/25 5:00', '2009/8/25 7:00', '2009/8/25 11:00', '2009/8/25 15:00', '2009/8/25 19:00', '2009/8/25 21:00', '2009/8/25 23:00', '2009/8/26 3:00', '2009/8/26 5:00', '2009/8/26 7:00', '2009/8/26 11:00', '2009/8/26 15:00', '2009/8/26 19:00', '2009/8/26 21:00', '2009/8/26 23:00', '2009/8/27 3:00', '2009/8/27 5:00', '2009/8/27 7:00', '2009/8/27 11:00', '2009/8/27 15:00', '2009/8/27 19:00', '2009/8/27 21:00', '2009/8/27 23:00', '2009/8/28 3:00', '2009/8/28 5:00', '2009/8/28 7:00', '2009/8/28 11:00', '2009/8/28 15:00', '2009/8/28 19:00', '2009/8/28 21:00', '2009/8/28 23:00', '2009/8/29 3:00', '2009/8/29 5:00', '2009/8/29 7:00', '2009/8/29 11:00', '2009/8/29 15:00', '2009/8/29 19:00', '2009/8/29 21:00', '2009/8/29 23:00', '2009/8/30 3:00', '2009/8/30 5:00', '2009/8/30 7:00', '2009/8/30 11:00', '2009/8/30 15:00', '2009/8/30 19:00', '2009/8/30 21:00', '2009/8/30 23:00', '2009/8/31 3:00', '2009/8/31 5:00', '2009/8/31 7:00', '2009/8/31 11:00', '2009/8/31 15:00', '2009/8/31 19:00', '2009/8/31 21:00', '2009/8/31 23:00', '2009/9/1 3:00', '2009/9/1 5:00', '2009/9/1 7:00', '2009/9/1 11:00', '2009/9/1 15:00', '2009/9/1 19:00', '2009/9/1 21:00', '2009/9/1 23:00', '2009/9/2 3:00', '2009/9/2 5:00', '2009/9/2 7:00', '2009/9/2 11:00', '2009/9/2 15:00', '2009/9/2 19:00', '2009/9/2 21:00', '2009/9/2 23:00', '2009/9/3 3:00', '2009/9/3 5:00', '2009/9/3 7:00', '2009/9/3 11:00', '2009/9/3 15:00', '2009/9/3 19:00', '2009/9/3 21:00', '2009/9/3 23:00', '2009/9/4 3:00', '2009/9/4 5:00', '2009/9/4 7:00', '2009/9/4 11:00', '2009/9/4 15:00', '2009/9/4 19:00', '2009/9/4 21:00', '2009/9/4 23:00', '2009/9/5 3:00', '2009/9/5 5:00', '2009/9/5 7:00', '2009/9/5 11:00', '2009/9/5 15:00', '2009/9/5 19:00', '2009/9/5 21:00', '2009/9/5 23:00', '2009/9/6 3:00', '2009/9/6 5:00', '2009/9/6 7:00', '2009/9/6 11:00', '2009/9/6 15:00', '2009/9/6 19:00', '2009/9/6 21:00', '2009/9/6 23:00', '2009/9/7 3:00', '2009/9/7 5:00', '2009/9/7 7:00', '2009/9/7 11:00', '2009/9/7 15:00', '2009/9/7 19:00', '2009/9/7 21:00', '2009/9/7 23:00', '2009/9/8 3:00', '2009/9/8 5:00', '2009/9/8 7:00', '2009/9/8 11:00', '2009/9/8 15:00', '2009/9/8 19:00', '2009/9/8 21:00', '2009/9/8 23:00', '2009/9/9 3:00', '2009/9/9 5:00', '2009/9/9 7:00', '2009/9/9 11:00', '2009/9/9 15:00', '2009/9/9 19:00', '2009/9/9 21:00', '2009/9/9 23:00', '2009/9/10 3:00', '2009/9/10 5:00', '2009/9/10 7:00', '2009/9/10 11:00', '2009/9/10 15:00', '2009/9/10 19:00', '2009/9/10 21:00', '2009/9/10 23:00', '2009/9/11 3:00', '2009/9/11 5:00', '2009/9/11 7:00', '2009/9/11 11:00', '2009/9/11 15:00', '2009/9/11 19:00', '2009/9/11 21:00', '2009/9/11 23:00', '2009/9/12 3:00', '2009/9/12 5:00', '2009/9/12 7:00', '2009/9/12 11:00', '2009/9/12 15:00', '2009/9/12 19:00', '2009/9/12 21:00', '2009/9/12 23:00', '2009/9/13 3:00', '2009/9/13 5:00', '2009/9/13 7:00', '2009/9/13 11:00', '2009/9/13 15:00', '2009/9/13 19:00', '2009/9/13 21:00', '2009/9/13 23:00', '2009/9/14 3:00', '2009/9/14 5:00', '2009/9/14 7:00', '2009/9/14 11:00', '2009/9/14 15:00', '2009/9/14 19:00', '2009/9/14 21:00', '2009/9/14 23:00', '2009/9/15 3:00', '2009/9/15 5:00', '2009/9/15 7:00', '2009/9/15 11:00', '2009/9/15 15:00', '2009/9/15 19:00', '2009/9/15 21:00', '2009/9/15 23:00', '2009/9/16 3:00', '2009/9/16 5:00', '2009/9/16 7:00', '2009/9/16 11:00', '2009/9/16 15:00', '2009/9/16 19:00', '2009/9/16 21:00', '2009/9/16 23:00', '2009/9/17 3:00', '2009/9/17 5:00', '2009/9/17 7:00', '2009/9/17 11:00', '2009/9/17 15:00', '2009/9/17 19:00', '2009/9/17 21:00', '2009/9/17 23:00', '2009/9/18 3:00', '2009/9/18 5:00', '2009/9/18 7:00', '2009/9/18 11:00', '2009/9/18 15:00', '2009/9/18 19:00', '2009/9/18 21:00', '2009/9/18 23:00', '2009/9/19 3:00', '2009/9/19 5:00', '2009/9/19 7:00', '2009/9/19 11:00', '2009/9/19 15:00', '2009/9/19 19:00', '2009/9/19 21:00', '2009/9/19 23:00', '2009/9/20 3:00', '2009/9/20 5:00', '2009/9/20 7:00', '2009/9/20 11:00', '2009/9/20 15:00', '2009/9/20 19:00', '2009/9/20 21:00', '2009/9/20 23:00', '2009/9/21 3:00', '2009/9/21 5:00', '2009/9/21 7:00', '2009/9/21 11:00', '2009/9/21 15:00', '2009/9/21 19:00', '2009/9/21 21:00', '2009/9/21 23:00', '2009/9/22 3:00', '2009/9/22 5:00', '2009/9/22 7:00', '2009/9/22 11:00', '2009/9/22 15:00', '2009/9/22 19:00', '2009/9/22 21:00', '2009/9/22 23:00', '2009/9/23 3:00', '2009/9/23 5:00', '2009/9/23 7:00', '2009/9/23 11:00', '2009/9/23 15:00', '2009/9/23 19:00', '2009/9/23 21:00', '2009/9/23 23:00', '2009/9/24 3:00', '2009/9/24 5:00', '2009/9/24 7:00', '2009/9/24 11:00', '2009/9/24 15:00', '2009/9/24 19:00', '2009/9/24 21:00', '2009/9/24 23:00', '2009/9/25 3:00', '2009/9/25 5:00', '2009/9/25 7:00', '2009/9/25 11:00', '2009/9/25 15:00', '2009/9/25 19:00', '2009/9/25 21:00', '2009/9/25 23:00', '2009/9/26 3:00', '2009/9/26 5:00', '2009/9/26 7:00', '2009/9/26 11:00', '2009/9/26 15:00', '2009/9/26 19:00', '2009/9/26 21:00', '2009/9/26 23:00', '2009/9/27 3:00', '2009/9/27 5:00', '2009/9/27 7:00', '2009/9/27 11:00', '2009/9/27 15:00', '2009/9/27 19:00', '2009/9/27 21:00', '2009/9/27 23:00', '2009/9/28 3:00', '2009/9/28 5:00', '2009/9/28 7:00', '2009/9/28 11:00', '2009/9/28 15:00', '2009/9/28 19:00', '2009/9/28 21:00', '2009/9/28 23:00', '2009/9/29 3:00', '2009/9/29 5:00', '2009/9/29 7:00', '2009/9/29 11:00', '2009/9/29 15:00', '2009/9/29 19:00', '2009/9/29 21:00', '2009/9/29 23:00', '2009/9/30 3:00', '2009/9/30 5:00', '2009/9/30 7:00', '2009/9/30 11:00', '2009/9/30 15:00', '2009/9/30 19:00', '2009/9/30 21:00', '2009/9/30 23:00', '2009/10/1 3:00', '2009/10/1 5:00', '2009/10/1 7:00', '2009/10/1 11:00', '2009/10/1 15:00', '2009/10/1 19:00', '2009/10/1 21:00', '2009/10/1 23:00', '2009/10/2 3:00', '2009/10/2 5:00', '2009/10/2 7:00', '2009/10/2 11:00', '2009/10/2 15:00', '2009/10/2 19:00', '2009/10/2 21:00', '2009/10/2 23:00', '2009/10/3 3:00', '2009/10/3 5:00', '2009/10/3 7:00', '2009/10/3 11:00', '2009/10/3 15:00', '2009/10/3 19:00', '2009/10/3 21:00', '2009/10/3 23:00', '2009/10/4 3:00', '2009/10/4 5:00', '2009/10/4 7:00', '2009/10/4 11:00', '2009/10/4 15:00', '2009/10/4 19:00', '2009/10/4 21:00', '2009/10/4 23:00', '2009/10/5 3:00', '2009/10/5 5:00', '2009/10/5 7:00', '2009/10/5 11:00', '2009/10/5 15:00', '2009/10/5 19:00', '2009/10/5 21:00', '2009/10/5 23:00', '2009/10/6 3:00', '2009/10/6 5:00', '2009/10/6 7:00', '2009/10/6 11:00', '2009/10/6 15:00', '2009/10/6 19:00', '2009/10/6 21:00', '2009/10/6 23:00', '2009/10/7 3:00', '2009/10/7 5:00', '2009/10/7 7:00', '2009/10/7 11:00', '2009/10/7 15:00', '2009/10/7 19:00', '2009/10/7 21:00', '2009/10/7 23:00', '2009/10/8 3:00', '2009/10/8 5:00', '2009/10/8 7:00', '2009/10/8 11:00', '2009/10/8 15:00', '2009/10/8 19:00', '2009/10/8 21:00', '2009/10/8 23:00', '2009/10/9 3:00', '2009/10/9 5:00', '2009/10/9 7:00', '2009/10/9 11:00', '2009/10/9 15:00', '2009/10/9 19:00', '2009/10/9 21:00', '2009/10/9 23:00', '2009/10/10 3:00', '2009/10/10 5:00', '2009/10/10 7:00', '2009/10/10 11:00', '2009/10/10 15:00', '2009/10/10 19:00', '2009/10/10 21:00', '2009/10/10 23:00', '2009/10/11 3:00', '2009/10/11 5:00', '2009/10/11 7:00', '2009/10/11 11:00', '2009/10/11 15:00', '2009/10/11 19:00', '2009/10/11 21:00', '2009/10/11 23:00', '2009/10/12 3:00', '2009/10/12 5:00', '2009/10/12 7:00', '2009/10/12 11:00', '2009/10/12 15:00', '2009/10/12 19:00', '2009/10/12 21:00', '2009/10/12 23:00', '2009/10/13 3:00', '2009/10/13 5:00', '2009/10/13 7:00', '2009/10/13 11:00', '2009/10/13 15:00', '2009/10/13 19:00', '2009/10/13 21:00', '2009/10/13 23:00', '2009/10/14 3:00', '2009/10/14 5:00', '2009/10/14 7:00', '2009/10/14 11:00', '2009/10/14 15:00', '2009/10/14 19:00', '2009/10/14 21:00', '2009/10/14 23:00', '2009/10/15 3:00', '2009/10/15 5:00', '2009/10/15 7:00', '2009/10/15 11:00', '2009/10/15 15:00', '2009/10/15 19:00', '2009/10/15 21:00', '2009/10/15 23:00', '2009/10/16 3:00', '2009/10/16 5:00', '2009/10/16 7:00', '2009/10/16 11:00', '2009/10/16 15:00', '2009/10/16 19:00', '2009/10/16 21:00', '2009/10/16 23:00', '2009/10/17 3:00', '2009/10/17 5:00', '2009/10/17 7:00', '2009/10/17 11:00', '2009/10/17 15:00', '2009/10/17 19:00', '2009/10/17 21:00', '2009/10/17 23:00', '2009/10/18 3:00', '2009/10/18 5:00', '2009/10/18 7:00']
import pandas as pd
df = pd.DataFrame({'Timestamp': timeData})
df["Timestamp"] = pd.to_datetime(df["Timestamp"], format="%Y/%m/%d %H:%M")
df['hours'] = df["Timestamp"].dt.strftime('%I%p').str.lower().str.lstrip('0')
df['days'] = df["Timestamp"].dt.day_name()
df = pd.crosstab(df['days'], df['hours']).reindex(index=df['days'].unique(), columns=df['hours'].unique())
df
hours 5am 7am 9am 1pm 3pm 5pm 9pm 1am 11am 7pm 11pm 6am 10am 2pm 4pm 6pm 10pm 12am 3am 4am 8am 12pm 8pm
days
Friday 18 14 6 6 17 6 18 4 12 13 15 0 0 0 0 0 0 1 13 0 0 0 0
Saturday 17 14 5 5 17 5 17 5 12 12 15 1 1 1 0 1 1 0 12 1 0 0 1
Sunday 19 15 6 6 18 6 18 6 12 12 16 0 0 0 0 0 0 0 13 0 0 0 0
Monday 18 14 6 6 18 6 18 6 12 12 16 0 0 0 0 0 0 0 12 0 0 0 0
Tuesday 16 14 5 4 17 5 16 6 13 13 16 1 1 1 1 1 1 0 12 0 0 0 0
Wednesday 16 14 4 4 16 5 16 3 14 14 15 0 0 0 0 0 0 1 13 0 0 0 0
Thursday 16 14 4 5 17 4 17 6 13 13 16 0 0 0 1 1 0 0 12 1 1 1 1
这里是一个使用 plotly 的方法的例子。数据被转换为长格式,并通过为 x 轴和 y 轴创建显示顺序列表来绘制图形。如果要限制时间轴,可以把原始数据提取到你需要的时间段再画出来。
df_long = df.groupby(['days','hours']).count()
df_long.reset_index(inplace=True)
df_long.head()
days hours Timestamp
0 Friday 11am 12
1 Friday 11pm 15
2 Friday 12am 1
3 Friday 1am 4
4 Friday 1pm 6
import plotly.express as px
order = {'hours':['5am', '6am', '7am', '8am', '9am', '10am', '11am', '12am',
'1pm', '2pm', '3pm', '4pm', '5pm', '6pm', '7pm', '8pm', '9pm', '10pm', '11pm', '12pm',
'1am', '2am', '3am', '4am']}
week_order = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
fig = px.scatter(df_long,
x='hours',
y='days',
size='Timestamp',
color='days',
category_orders=order)
fig.update_yaxes(categoryarray=week_order)
fig.show()
牵牛星 还有另一个图形库,Altair. It has the advantage that the data can be used directly with pandas. See this page。
import altair as alt
from vega_datasets import data
df['count'] = 1
df['Timestamp'] = pd.to_datetime(df['Timestamp'])
alt.Chart(df).mark_circle().encode(
x='hours(Timestamp):O',
y='day(Timestamp):O',
size='sum(count):Q'
)
Python、Numpy 和 Matplotlib
数据排序后,简单画7个散点图, 注意关闭所有不需要的视觉元素(左, 顶部、右侧书脊和 y 刻度和刻度标签)。
简单说一下使用默认的属性周期是强制的 在轴之间共享,因此每个轴的颜色都不同。
import numpy as np
import matplotlib.pyplot as plt
# Some constants that will be useful later (I find writing list of strings
# boring and error prone, I prefer to split a string of space separated items)
AMPM_TO_24 = dict(
zip('12a 1a 2a 3a 4a 5a 6a 7a 8a 9a 10a 11a 12p 1p 2p 3p 4p 5p 6p 7p 8p 9p 10p 11p'.split(),
'0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23'.split()))
DAYS_OW = 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'.split()
# I have slightly edited your data: ① shortened am/mp ② used commas
data = '''\
hour, 5a,7a,9a,1p,3p,5p,9p,1a,11a,7p,11p,6a,10a,2p,4p,6p,10p,12a,3a,4a,8a,12p,8p
Friday, 18,14, 6, 6,17, 6,18, 4, 12,13, 15, 0, 0, 0, 0, 0, 0, 1,13, 0, 0, 0, 0
Saturday, 17,14, 5, 5,17, 5,17, 5, 12,12, 15, 1, 1, 1, 0, 1, 1, 0,12, 1, 0, 0, 1
Sunday, 19,15, 6, 6,18, 6,18, 6, 12,12, 16, 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 0
Monday, 18,14, 6, 6,18, 6,18, 6, 12,12, 16, 0, 0, 0, 0, 0, 0, 0,12, 0, 0, 0, 0
Tuesday, 16,14, 5, 4,17, 5,16, 6, 13,13, 16, 1, 1, 1, 1, 1, 1, 0,12, 0, 0, 0, 0
Wednesday,16,14, 4, 4,16, 5,16, 3, 14,14, 15, 0, 0, 0, 0, 0, 0, 1,13, 0, 0, 0, 0
Thursday, 16,14, 4, 5,17, 4,17, 6, 13,13, 16, 0, 0, 0, 1, 1, 0, 0,12, 1, 1, 1, 1'''.split('\n')
# ① extract hours from 1st line, ② convert to 0÷24 and place in a Numpy array
_, *hours = (h.strip() for h in data[0].split(','))
hours = np.array([AMPM_TO_24[h] for h in hours], dtype=int)
zero = np.zeros_like(hours)
# ① generator of list of items, ② convert data to dict, its values are Numpy arrays
csv = (line.split(',') for line in data[1:])
data = {dow:np.array(values, dtype=int) for dow, *values in csv}
################### PLOTTING STARTS HERE ################
# sharey=all because I want the same scale for all the circles
fig, axes = plt.subplots(7, figsize=(9, 6),
sharey='all', constrained_layout=1)
# prop_cycle is renewed for each Axes, we want a single instance for the figure
fig_prop_cycle = plt.rcParams['axes.prop_cycle']()
for ax, dow in zip(axes, DAYS_OW[::-1]):
#or ax, dow in zip(axes, data): # alternative order of plots
ax.scatter(hours, [0 for _ in hours], 4*data[dow]**2, **next(fig_prop_cycle), alpha=0.6)
for x in 'left top right'.split():ax.spines[x].set_visible(False)
ax.set_xticks(range(0,24,3)) ; ax.set_xlim((-1, 25))
ax.set_xticks(range(25), minor=True)
ax.set_yticks([]) ; ax.set_yticklabels([])
ax.set_ylabel(dow, rotation=0, ha='right', va='center', fontsize=12, fontweight='bold')
plt.show()
关于以前的版本,我没有意识到对 values
和
后来对 hours
进行排序是一种空操作(请参阅编辑历史记录)。
回复:日期的排序。
我觉得这种类型的图表读起来就像一页文字, 从上到下,与常见的情节相反 纵坐标是从下到上排列的,因此我的想法是, 在此答案的先前修订版中提出, 其中星期几按以下顺序显示 它们在周五到周四的数据中被发现。
- 更新:为什么是黑色/灰色配色方案。我在暗模式下看 SO。样本图必须是透明的,所以它看起来是黑色/灰色。当我查看 phone 上的问题时,我才意识到情况并非如此,该问题未设置为使用 SO 暗模式。需要更改的内容在代码中很明显,我没有时间更改答案。
- 使用
seaborn.scatterplot
- 使用
sizes=(50, 1000)
调整气泡大小。0
的大小为50
,最大值的大小为1000
。将50
更改为0
以获得0
大小0
值。
- 使用
- 使用您的示例数据框
df
,到.crosstab
之前的点hours
应该在索引上,因为索引成为 x 轴
- 按照代码中的注释设置变量轴和图形参数,以生成所需的图
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# beginning with your dataframe before doing the crosstab, create the crosstab as follows
ct = pd.crosstab(df.hours, df.days)
# the data is missing anything for 2am add that to ct as 0s
missing = pd.DataFrame({'Friday': [0], 'Monday': [0], 'Saturday': [0], 'Sunday': [0], 'Thursday': [0], 'Tuesday': [0], 'Wednesday': [0]}, index=['2am'])
ct = ct.append(missing)
# sorted column and axis values
hours = ['5am', '6am', '7am', '8am', '9am', '10am', '11am', '12am', '1pm', '2pm', '3pm', '4pm', '5pm', '6pm', '7pm', '8pm', '9pm', '10pm', '11pm', '12pm', '1am', '2am', '3am', '4am']
days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
# colors for plots
colors = ['purple', 'lime', 'yellow', 'red', 'blue', 'green', 'orange']
# reorder the index and columns
ct = ct.loc[hours, days]
# create the figure
fig, axes = plt.subplots(nrows=7, figsize=(14, 7), facecolor='black', constrained_layout=1)
# iterate through days, axes, and colors
for col, ax, color in zip(days, axes, colors):
# select data
data = ct[col].reset_index()
# plot
sns.scatterplot(data=data, x='index', y=[0]*len(data), size=col, ax=ax, color=color, legend=False, ec='none', sizes=(50, 1000), palette='muted', alpha=0.5)
# Hide the right and top spines
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
# set the y-tick name
ax.set_yticks([0])
ax.set_yticklabels([col])
# remove the x-axis label
ax.set_xlabel('')
# set the x margin
ax.margins(x=0.02)
# set the plot facecolor
ax.set_facecolor('black')
# set axis labels, ticklabels and tick colors
ax.tick_params(colors='gray', which='both')
# set spine color
ax.spines['bottom'].set(color='gray')
display(ct)
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
5am 19 18 16 16 16 18 17
6am 0 0 1 0 0 0 1
7am 15 14 14 14 14 14 14
8am 0 0 0 0 1 0 0
9am 6 6 5 4 4 6 5
10am 0 0 1 0 0 0 1
11am 12 12 13 14 13 12 12
12am 0 0 0 1 0 1 0
1pm 6 6 4 4 5 6 5
2pm 0 0 1 0 0 0 1
3pm 18 18 17 16 17 17 17
4pm 0 0 1 0 1 0 0
5pm 6 6 5 5 4 6 5
6pm 0 0 1 0 1 0 1
7pm 12 12 13 14 13 13 12
8pm 0 0 0 0 1 0 1
9pm 18 18 16 16 17 18 17
10pm 0 0 1 0 0 0 1
11pm 16 16 16 15 16 15 15
12pm 0 0 0 0 1 0 0
1am 6 6 6 3 6 4 5
2am 0 0 0 0 0 0 0
3am 13 12 12 13 12 13 12
4am 0 0 0 0 1 0 1