Plot three series on the same plot grouping data by day and month

I have a dataset containing three years of data which I would like to plot and compare by date and month; but, I am having a hard time with the final result.

I am nearly there, but for some strange reason, while plotting I continue to get an annoying gap in between the data points, even if this does not seem to be included in the data series.

The whole dataset is this:

    Day Visits
0   2018-04-01  1
1   2018-04-02  1
2   2018-04-03  3
3   2018-04-04  3
4   2018-04-05  5
5   2018-04-06  10
6   2018-04-07  6
7   2018-04-08  0
8   2018-04-09  7
9   2018-04-10  7
10  2018-04-11  5
11  2018-04-12  5
12  2018-04-13  7
13  2018-04-14  1
14  2018-04-15  1
15  2018-04-16  4
16  2018-04-17  3
17  2018-04-18  3
18  2018-04-19  8
19  2018-04-20  1
20  2018-04-21  0
21  2018-04-22  1
22  2018-04-23  1
23  2018-04-24  7
24  2018-04-25  3
25  2018-04-26  5
26  2018-04-27  2
27  2018-04-28  1
28  2018-04-29  0
29  2018-04-30  0
30  2018-05-01  2
31  2018-05-02  3
32  2018-05-03  6
33  2018-05-04  9
34  2018-05-05  1
35  2018-05-06  3
36  2018-05-07  7
37  2018-05-08  3
38  2018-05-09  6
39  2018-05-10  4
40  2018-05-11  3
41  2018-05-12  3
42  2018-05-13  0
43  2018-05-14  5
44  2018-05-15  7
45  2018-05-16  5
46  2018-05-17  6
47  2018-05-18  7
48  2018-05-19  2
49  2018-05-20  2
50  2018-05-21  9
51  2018-05-22  10
52  2018-05-23  6
53  2018-05-24  8
54  2018-05-25  5
55  2018-05-26  2
56  2018-05-27  3
57  2018-05-28  4
58  2018-05-29  5
59  2018-05-30  6
60  2018-05-31  1
61  2018-06-01  3
62  2018-06-02  1
63  2018-06-03  1
64  2018-06-04  4
65  2018-06-05  5
66  2018-06-06  5
67  2018-06-07  7
68  2018-06-08  4
69  2018-06-09  1
70  2018-06-10  1
71  2018-06-11  5
72  2018-06-12  4
73  2018-06-13  6
74  2018-06-14  7
75  2018-06-15  4
76  2018-06-16  1
77  2018-06-17  2
78  2018-06-18  4
79  2018-06-19  3
80  2018-06-20  0
81  2018-06-21  4
82  2018-06-22  8
83  2018-06-23  0
84  2018-06-24  1
85  2018-06-25  7
86  2018-06-26  8
87  2018-06-27  2
88  2018-06-28  2
89  2018-06-29  10
90  2018-06-30  3
91  2018-07-01  0
92  2018-07-02  3
93  2018-07-03  3
94  2018-07-04  4
95  2018-07-05  3
96  2018-07-06  5
97  2018-07-07  4
98  2018-07-08  2
99  2018-07-09  3
100 2018-07-10  6
101 2018-07-11  4
102 2018-07-12  7
103 2018-07-13  3
104 2018-07-14  1
105 2018-07-15  2
106 2018-07-16  7
107 2018-07-17  4
108 2018-07-18  5
109 2018-07-19  4
110 2018-07-20  5
111 2018-07-21  6
112 2018-07-22  0
113 2018-07-23  9
114 2018-07-24  1
115 2018-07-25  4
116 2018-07-26  4
117 2018-07-27  4
118 2018-07-28  1
119 2018-07-29  1
120 2018-07-30  4
121 2018-07-31  2
122 2018-08-01  2
123 2018-08-02  6
124 2018-08-03  6
125 2018-08-04  0
126 2018-08-05  2
127 2018-08-06  3
128 2018-08-07  5
129 2018-08-08  3
130 2018-08-09  6
131 2018-08-10  2
132 2018-08-11  1
133 2018-08-12  1
134 2018-08-13  4
135 2018-08-14  4
136 2018-08-15  1
137 2018-08-16  3
138 2018-08-17  3
139 2018-08-18  3
140 2018-08-19  7
141 2018-08-20  5
142 2018-08-21  3
143 2018-08-22  6
144 2018-08-23  5
145 2018-08-24  9
146 2018-08-25  7
147 2018-08-26  1
148 2018-08-27  8
149 2018-08-28  6
150 2018-08-29  9
151 2018-08-30  5
152 2018-08-31  5
153 2018-09-01  5
154 2018-09-02  0
155 2018-09-03  8
156 2018-09-04  9
157 2018-09-05  2
158 2018-09-06  6
159 2018-09-07  9
160 2018-09-08  1
161 2018-09-09  3
162 2018-09-10  6
163 2018-09-11  9
164 2018-09-12  9
165 2018-09-13  7
166 2018-09-14  11
167 2018-09-15  5
168 2018-09-16  3
169 2018-09-17  5
170 2018-09-18  4
171 2018-09-19  5
172 2018-09-20  8
173 2018-09-21  3
174 2018-09-22  2
175 2018-09-23  6
176 2018-09-24  4
177 2018-09-25  6
178 2018-09-26  13
179 2018-09-27  6
180 2018-09-28  2
181 2018-09-29  3
182 2018-09-30  7
183 2018-10-01  9
184 2018-10-02  9
185 2018-10-03  5
186 2018-10-04  2
187 2018-10-05  4
188 2018-10-06  2
189 2018-10-07  2
190 2018-10-08  6
191 2018-10-09  9
192 2018-10-10  6
193 2018-10-11  9
194 2018-10-12  7
195 2018-10-13  3
196 2018-10-14  2
197 2018-10-15  5
198 2018-10-16  7
199 2018-10-17  7
200 2018-10-18  2
201 2018-10-19  5
202 2018-10-20  1
203 2018-10-21  0
204 2018-10-22  3
205 2018-10-23  5
206 2018-10-24  11
207 2018-10-25  4
208 2018-10-26  7
209 2018-10-27  2
210 2018-10-28  3
211 2018-10-29  3
212 2018-10-30  6
213 2018-10-31  3
214 2018-11-01  0
215 2018-11-02  3
216 2018-11-03  2
217 2018-11-04  3
218 2018-11-05  4
219 2018-11-06  11
220 2018-11-07  5
221 2018-11-08  7
222 2018-11-09  4
223 2018-11-10  2
224 2018-11-11  3
225 2018-11-12  3
226 2018-11-13  4
227 2018-11-14  9
228 2018-11-15  8
229 2018-11-16  3
230 2018-11-17  2
231 2018-11-18  1
232 2018-11-19  5
233 2018-11-20  2
234 2018-11-21  4
235 2018-11-22  7
236 2018-11-23  5
237 2018-11-24  3
238 2018-11-25  2
239 2018-11-26  1
240 2018-11-27  2
241 2018-11-28  4
242 2018-11-29  8
243 2018-11-30  1
244 2018-12-01  2
245 2018-12-02  2
246 2018-12-03  6
247 2018-12-04  4
248 2018-12-05  9
249 2018-12-06  4
250 2018-12-07  5
251 2018-12-08  2
252 2018-12-09  2
253 2018-12-10  7
254 2018-12-11  4
255 2018-12-12  4
256 2018-12-13  9
257 2018-12-14  7
258 2018-12-15  0
259 2018-12-16  2
260 2018-12-17  6
261 2018-12-18  6
262 2018-12-19  5
263 2018-12-20  4
264 2018-12-21  2
265 2018-12-22  0
266 2018-12-23  6
267 2018-12-24  1
268 2018-12-25  0
269 2018-12-26  1
270 2018-12-27  5
271 2018-12-28  4
272 2018-12-29  2
273 2018-12-30  5
274 2018-12-31  1
275 2019-01-01  2
276 2019-01-02  10
277 2019-01-03  3
278 2019-01-04  3
279 2019-01-05  3
280 2019-01-06  0
281 2019-01-07  8
282 2019-01-08  5
283 2019-01-09  7
284 2019-01-10  9
285 2019-01-11  10
286 2019-01-12  1
287 2019-01-13  5
288 2019-01-14  9
289 2019-01-15  8
290 2019-01-16  4
291 2019-01-17  7
292 2019-01-18  5
293 2019-01-19  5
294 2019-01-20  2
295 2019-01-21  9
296 2019-01-22  8
297 2019-01-23  5
298 2019-01-24  9
299 2019-01-25  11
300 2019-01-26  3
301 2019-01-27  3
302 2019-01-28  3
303 2019-01-29  6
304 2019-01-30  8
305 2019-01-31  7
306 2019-02-01  10
307 2019-02-02  8
308 2019-02-03  2
309 2019-02-04  10
310 2019-02-05  2
311 2019-02-06  2
312 2019-02-07  7
313 2019-02-08  8
314 2019-02-09  9
315 2019-02-10  5
316 2019-02-11  14
317 2019-02-12  14
318 2019-02-13  6
319 2019-02-14  6
320 2019-02-15  15
321 2019-02-16  3
322 2019-02-17  2
323 2019-02-18  11
324 2019-02-19  17
325 2019-02-20  11
326 2019-02-21  9
327 2019-02-22  6
328 2019-02-23  8
329 2019-02-24  4
330 2019-02-25  11
331 2019-02-26  15
332 2019-02-27  15
333 2019-02-28  15
334 2019-03-01  13
335 2019-03-02  0
336 2019-03-03  3
337 2019-03-04  12
338 2019-03-05  16
339 2019-03-06  15
340 2019-03-07  17
341 2019-03-08  12
342 2019-03-09  4
343 2019-03-10  6
344 2019-03-11  9
345 2019-03-12  10
346 2019-03-13  14
347 2019-03-14  11
348 2019-03-15  6
349 2019-03-16  3
350 2019-03-17  0
351 2019-03-18  15
352 2019-03-19  17
353 2019-03-20  5
354 2019-03-21  12
355 2019-03-22  13
356 2019-03-23  1
357 2019-03-24  2
358 2019-03-25  13
359 2019-03-26  14
360 2019-03-27  13
361 2019-03-28  19
362 2019-03-29  14
363 2019-03-30  1
364 2019-03-31  2
365 2019-04-01  15
366 2019-04-02  16
367 2019-04-03  18
368 2019-04-04  19
369 2019-04-05  12
370 2019-04-06  3
371 2019-04-07  5
372 2019-04-08  12
373 2019-04-09  22
374 2019-04-10  13
375 2019-04-11  20
376 2019-04-12  9
377 2019-04-13  5
378 2019-04-14  3
379 2019-04-15  12
380 2019-04-16  10
381 2019-04-17  9
382 2019-04-18  16
383 2019-04-19  8
384 2019-04-20  2
385 2019-04-21  4
386 2019-04-22  4
387 2019-04-23  9
388 2019-04-24  13
389 2019-04-25  5
390 2019-04-26  8
391 2019-04-27  1
392 2019-04-28  2
393 2019-04-29  7
394 2019-04-30  19
395 2019-05-01  3
396 2019-05-02  7
397 2019-05-03  12
398 2019-05-04  4
399 2019-05-05  0
400 2019-05-06  13
401 2019-05-07  8
402 2019-05-08  10
403 2019-05-09  9
404 2019-05-10  9
405 2019-05-11  1
406 2019-05-12  4
407 2019-05-13  8
408 2019-05-14  7
409 2019-05-15  11
410 2019-05-16  11
411 2019-05-17  12
412 2019-05-18  4
413 2019-05-19  4
414 2019-05-20  16
415 2019-05-21  12
416 2019-05-22  9
417 2019-05-23  10
418 2019-05-24  6
419 2019-05-25  2
420 2019-05-26  2
421 2019-05-27  8
422 2019-05-28  16
423 2019-05-29  16
424 2019-05-30  11
425 2019-05-31  8
426 2019-06-01  5
427 2019-06-02  5
428 2019-06-03  13
429 2019-06-04  12
430 2019-06-05  17
431 2019-06-06  5
432 2019-06-07  10
433 2019-06-08  1
434 2019-06-09  1
435 2019-06-10  8
436 2019-06-11  9
437 2019-06-12  5
438 2019-06-13  4
439 2019-06-14  7
440 2019-06-15  2
441 2019-06-16  1
442 2019-06-17  15
443 2019-06-18  8
444 2019-06-19  10
445 2019-06-20  13
446 2019-06-21  9
447 2019-06-22  2
448 2019-06-23  1
449 2019-06-24  15
450 2019-06-25  14
451 2019-06-26  14
452 2019-06-27  9
453 2019-06-28  11
454 2019-06-29  0
455 2019-06-30  0
456 2019-07-01  14
457 2019-07-02  12
458 2019-07-03  3
459 2019-07-04  11
460 2019-07-05  12
461 2019-07-06  1
462 2019-07-07  2
463 2019-07-08  6
464 2019-07-09  12
465 2019-07-10  12
466 2019-07-11  13
467 2019-07-12  9
468 2019-07-13  3
469 2019-07-14  1
470 2019-07-15  11
471 2019-07-16  15
472 2019-07-17  12
473 2019-07-18  7
474 2019-07-19  12
475 2019-07-20  1
476 2019-07-21  3
477 2019-07-22  6
478 2019-07-23  6
479 2019-07-24  7
480 2019-07-25  7
481 2019-07-26  11
482 2019-07-27  0
483 2019-07-28  3
484 2019-07-29  5
485 2019-07-30  6
486 2019-07-31  5
487 2019-08-01  10
488 2019-08-02  9
489 2019-08-03  0
490 2019-08-04  2
491 2019-08-05  7
492 2019-08-06  7
493 2019-08-07  10
494 2019-08-08  10
495 2019-08-09  1
496 2019-08-10  1
497 2019-08-11  0
498 2019-08-12  8
499 2019-08-13  0
500 2019-08-14  1
501 2019-08-15  0
502 2019-08-16  2
503 2019-08-17  1
504 2019-08-18  1
505 2019-08-19  4
506 2019-08-20  1
507 2019-08-21  4
508 2019-08-22  3
509 2019-08-23  0
510 2019-08-24  0
511 2019-08-25  0
512 2019-08-26  4
513 2019-08-27  7
514 2019-08-28  1
515 2019-08-29  3
516 2019-08-30  1
517 2019-08-31  4
518 2019-09-01  2
519 2019-09-02  4
520 2019-09-03  8
521 2019-09-04  1
522 2019-09-05  1
523 2019-09-06  2
524 2019-09-07  2
525 2019-09-08  1
526 2019-09-09  7
527 2019-09-10  4
528 2019-09-11  3
529 2019-09-12  1
530 2019-09-13  3
531 2019-09-14  2
532 2019-09-15  1
533 2019-09-16  2
534 2019-09-17  1
535 2019-09-18  6
536 2019-09-19  6
537 2019-09-20  6
538 2019-09-21  1
539 2019-09-22  0
540 2019-09-23  1
541 2019-09-24  3
542 2019-09-25  4
543 2019-09-26  7
544 2019-09-27  3
545 2019-09-28  0
546 2019-09-29  1
547 2019-09-30  2
548 2019-10-01  4
549 2019-10-02  3
550 2019-10-03  13
551 2019-10-04  11
552 2019-10-05  0
553 2019-10-06  0
554 2019-10-07  2
555 2019-10-08  3
556 2019-10-09  3
557 2019-10-10  2
558 2019-10-11  5
559 2019-10-12  3
560 2019-10-13  3
561 2019-10-14  4
562 2019-10-15  3
563 2019-10-16  3
564 2019-10-17  1
565 2019-10-18  4
566 2019-10-19  0
567 2019-10-20  2
568 2019-10-21  3
569 2019-10-22  2
570 2019-10-23  5
571 2019-10-24  6
572 2019-10-25  10
573 2019-10-26  3
574 2019-10-27  6
575 2019-10-28  2
576 2019-10-29  3
577 2019-10-30  7
578 2019-10-31  3
579 2019-11-01  2
580 2019-11-02  0
581 2019-11-03  1
582 2019-11-04  8
583 2019-11-05  4
584 2019-11-06  4
585 2019-11-07  3
586 2019-11-08  3
587 2019-11-09  2
588 2019-11-10  0
589 2019-11-11  1
590 2019-11-12  6
591 2019-11-13  7
592 2019-11-14  6
593 2019-11-15  2
594 2019-11-16  1
595 2019-11-17  6
596 2019-11-18  1
597 2019-11-19  5
598 2019-11-20  8
599 2019-11-21  5
600 2019-11-22  6
601 2019-11-23  1
602 2019-11-24  5
603 2019-11-25  8
604 2019-11-26  3
605 2019-11-27  5
606 2019-11-28  6
607 2019-11-29  5
608 2019-11-30  2
609 2019-12-01  2
610 2019-12-02  5
611 2019-12-03  2
612 2019-12-04  8
613 2019-12-05  3
614 2019-12-06  7
615 2019-12-07  0
616 2019-12-08  2
617 2019-12-09  3
618 2019-12-10  7
619 2019-12-11  9
620 2019-12-12  7
621 2019-12-13  4
622 2019-12-14  4
623 2019-12-15  1
624 2019-12-16  1
625 2019-12-17  7
626 2019-12-18  13
627 2019-12-19  6
628 2019-12-20  2
629 2019-12-21  4
630 2019-12-22  0
631 2019-12-23  4
632 2019-12-24  0
633 2019-12-25  0
634 2019-12-26  0
635 2019-12-27  1
636 2019-12-28  3
637 2019-12-29  0
638 2019-12-30  3
639 2019-12-31  1
640 2020-01-01  1
641 2020-01-02  2
642 2020-01-03  3
643 2020-01-04  0
644 2020-01-05  1
645 2020-01-06  2
646 2020-01-07  10
647 2020-01-08  7
648 2020-01-09  9
649 2020-01-10  5
650 2020-01-11  2
651 2020-01-12  0
652 2020-01-13  4
653 2020-01-14  5
654 2020-01-15  10
655 2020-01-16  9
656 2020-01-17  6
657 2020-01-18  0
658 2020-01-19  4
659 2020-01-20  8
660 2020-01-21  2
661 2020-01-22  9
662 2020-01-23  2
663 2020-01-24  9
664 2020-01-25  0
665 2020-01-26  1
666 2020-01-27  6
667 2020-01-28  10
668 2020-01-29  9
669 2020-01-30  5
670 2020-01-31  6
671 2020-02-01  2
672 2020-02-02  1
673 2020-02-03  6
674 2020-02-04  15
675 2020-02-05  8
676 2020-02-06  4
677 2020-02-07  7
678 2020-02-08  3
679 2020-02-09  0
680 2020-02-10  3
681 2020-02-11  10
682 2020-02-12  7
683 2020-02-13  4
684 2020-02-14  3
685 2020-02-15  4
686 2020-02-16  3
687 2020-02-17  6
688 2020-02-18  6
689 2020-02-19  11
690 2020-02-20  8
691 2020-02-21  5
692 2020-02-22  1
693 2020-02-23  3
694 2020-02-24  4
695 2020-02-25  20
696 2020-02-26  15
697 2020-02-27  16
698 2020-02-28  15
699 2020-02-29  4
700 2020-03-01  7
701 2020-03-02  16
702 2020-03-03  24
703 2020-03-04  14
704 2020-03-05  20
705 2020-03-06  23
706 2020-03-07  2
707 2020-03-08  2
708 2020-03-09  12
709 2020-03-10  17
710 2020-03-11  23
711 2020-03-12  11
712 2020-03-13  18
713 2020-03-14  2
714 2020-03-15  1
715 2020-03-16  15
716 2020-03-17  21
717 2020-03-18  16
718 2020-03-19  19
719 2020-03-20  18
720 2020-03-21  1
721 2020-03-22  3
722 2020-03-23  7
723 2020-03-24  3
724 2020-03-25  2
725 2020-03-26  3
726 2020-03-27  2
727 2020-03-28  4
728 2020-03-29  4
729 2020-03-30  6
730 2020-03-31  6
731 2020-04-01  5
732 2020-04-02  16
733 2020-04-03  18
734 2020-04-04  16
735 2020-04-05  10
736 2020-04-06  27
737 2020-04-07  10
738 2020-04-08  14
739 2020-04-09  10
740 2020-04-10  11
741 2020-04-11  9
742 2020-04-12  8
743 2020-04-13  6
744 2020-04-14  14
745 2020-04-15  9
746 2020-04-16  11
747 2020-04-17  17
748 2020-04-18  22
749 2020-04-19  17
750 2020-04-20  15
751 2020-04-21  17
752 2020-04-22  17
753 2020-04-23  25
754 2020-04-24  22
755 2020-04-25  11
756 2020-04-26  7
757 2020-04-27  21
758 2020-04-28  17
759 2020-04-29  11
760 2020-04-30  16
761 2020-05-01  6
762 2020-05-02  2
763 2020-05-03  8
764 2020-05-04  18
765 2020-05-05  24
766 2020-05-06  12
767 2020-05-07  20
768 2020-05-08  4
769 2020-05-09  5

What I would like to do is:

a) Subset the data to print. I, in fact, need to concentrate just on 3 months, but it can be three days b) I would like the x label to be shown as day and month only (if I keep the year, data will be shown consecutively and no comparison will be possible)

In doing this, I have remapped the Day column as in %_m%d so as to be able to order data progressively and then set that as the index.

This also allowed me to apply a mask as mask = ((test.Day = 301) (test.Day = 430)). In this case, I'm getting the whole period of March till the end of April.

Finally, the dataset has been pivoted giving me something like:

However, when I plot the above, I get the following incorrect output:

Note that the labels (which have been overwritten with a custom formatter) are in an order that is the one passed through and also the big gap. I somehow overcomplicating things here, but I wasn't able to figure out another option to start with.

I have also tried a different approach, so treating the three plots separately, but again in the end I always get some unexpected plotline joined together even if they should not.

Any help?

Topic matplotlib plotting dataframe

Category Data Science


Ok, I found out the problem.

My attempt to format the date as in DD/MM using a progressive number technique is working, but numerically speaking it adds some "gaps" between the months.

To solve, an index reset after the label re-mapping is required.

That being said, I'm still not sure I'm using the right approach. Somehow I feel there is something simpler I am missing out.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.