I'm new to python and I'm trying to plot a line graph of two data series using matplotlib.
Here's the sample code and data:
import matplotlib.pyplot as plt
# choronologically sorted dates with frequencies
date_1 = ['2018-06-06', '2018-06-07', '2018-06-08', '2018-06-09', '2018-06-10', '2018-06-11', '2018-06-12', '2018-06-13', '2018-06-14', '2018-06-15', '2018-06-16', '2018-06-17', '2018-06-18', '2018-06-19', '2018-06-20', '2018-06-21', '2018-06-22', '2018-06-23', '2018-06-25', '2018-06-27', '2018-06-28', '2018-06-30', '2018-07-01', '2018-07-02', '2018-07-03', '2018-07-04', '2018-07-05', '2018-07-06', '2018-07-07', '2018-07-08', '2018-07-09', '2018-07-10', '2018-07-11', '2018-07-12', '2018-07-13', '2018-07-14', '2018-07-15', '2018-07-16', '2018-07-17', '2018-07-18', '2018-07-19', '2018-07-20', '2018-07-21', '2018-07-22', '2018-07-23', '2018-07-24', '2018-07-25', '2018-07-26', '2018-07-27', '2018-07-28', '2018-07-29', '2018-07-30', '2018-07-31', '2018-08-01', '2018-08-02', '2018-08-03', '2018-08-04', '2018-08-05', '2018-08-06', '2018-08-07', '2018-08-08', '2018-08-09', '2018-08-10', '2018-08-11', '2018-08-12', '2018-08-13', '2018-08-14', '2018-08-15', '2018-08-16', '2018-08-17', '2018-08-18', '2018-08-19', '2018-08-20', '2018-08-21', '2018-08-22', '2018-08-23', '2018-08-24', '2018-08-25', '2018-08-26', '2018-08-27', '2018-08-28', '2018-08-29', '2018-08-30', '2018-08-31', '2018-09-01', '2018-09-02', '2018-09-03', '2018-09-04', '2018-09-05', '2018-09-06', '2018-09-07', '2018-09-08', '2018-09-09', '2018-09-10', '2018-09-11', '2018-09-12', '2018-09-13', '2018-09-14', '2018-09-15', '2018-09-16', '2018-09-17', '2018-09-18', '2018-09-19', '2018-09-20', '2018-09-21', '2018-09-22', '2018-09-23', '2018-09-24', '2018-09-25', '2018-09-26', '2018-09-27', '2018-09-28', '2018-09-29', '2018-09-30', '2018-10-01', '2018-10-02', '2018-10-03', '2018-10-04', '2018-10-05', '2018-10-06', '2018-10-07', '2018-10-08', '2018-10-09', '2018-10-10', '2018-10-11', '2018-10-12', '2018-10-13', '2018-10-14', '2018-10-15', '2018-10-16', '2018-10-17', '2018-10-18', '2018-10-19', '2018-10-20', '2018-10-21', '2018-10-22', '2018-10-23', '2018-10-24', '2018-10-25', '2018-10-26', '2018-10-27', '2018-10-28', '2018-10-29', '2018-10-30', '2018-10-31', '2018-11-01', '2018-11-02', '2018-11-03', '2018-11-04', '2018-11-05', '2018-11-06', '2018-11-07', '2018-11-08', '2018-11-09', '2018-11-10', '2018-11-11', '2018-11-12', '2018-11-13', '2018-11-14', '2018-11-15', '2018-11-16', '2018-11-17', '2018-11-18', '2018-11-19', '2018-11-20', '2018-11-21', '2018-11-22', '2018-11-23', '2018-11-24', '2018-11-25', '2018-11-26', '2018-11-27', '2018-11-28']
freq_1 = [87, 123, 147, 170, 118, 23, 9, 87, 118, 297, 139, 650, 95, 336, 338, 276, 56, 474, 2, 1, 1, 576, 292, 211, 25, 20, 11, 91, 84, 43, 280, 33, 198, 88, 25, 36, 46, 14, 44, 112, 76, 15, 42, 124, 54, 132, 271, 230, 728, 35, 251, 163, 41, 89, 50, 257, 48, 26, 73, 204, 19, 39, 58, 222, 48, 129, 286, 191, 121, 84, 20, 13, 157, 66, 180, 10, 36, 298, 162, 274, 21, 298, 243, 21, 79, 199, 12, 48, 212, 141, 62, 308, 339, 296, 479, 174, 90, 389, 120, 256, 327, 131, 451, 447, 279, 37, 51, 105, 578, 298, 184, 347, 59, 276, 379, 117, 158, 162, 64, 36, 102, 127, 131, 61, 46, 124, 202, 650, 183, 119, 44, 18, 28, 26, 126, 103, 34, 66, 109, 91, 155, 109, 172, 76, 91, 67, 840, 56, 126, 55, 144, 39, 63, 62, 242, 41, 64, 83, 78, 53, 35, 30, 38, 59, 238, 110, 116, 79, 91, 38, 633, 176, 56]
date_2 = ['2018-06-06', '2018-06-07', '2018-06-08', '2018-06-09', '2018-06-10', '2018-06-11', '2018-06-12', '2018-06-13', '2018-06-14', '2018-06-15', '2018-06-16', '2018-06-17', '2018-06-18', '2018-06-19', '2018-06-20', '2018-06-21', '2018-06-22', '2018-06-23', '2018-06-25', '2018-06-28', '2018-06-29', '2018-06-30', '2018-07-01', '2018-07-02', '2018-07-03', '2018-07-04', '2018-07-05', '2018-07-06', '2018-07-07', '2018-07-08', '2018-07-09', '2018-07-10', '2018-07-11', '2018-07-12', '2018-07-13', '2018-07-14', '2018-07-15', '2018-07-16', '2018-07-17', '2018-07-18', '2018-07-19', '2018-07-20', '2018-07-21', '2018-07-22', '2018-07-23', '2018-07-24', '2018-07-25', '2018-07-26', '2018-07-27', '2018-07-28', '2018-07-29', '2018-07-30', '2018-07-31', '2018-08-01', '2018-08-02', '2018-08-03', '2018-08-04', '2018-08-05', '2018-08-06', '2018-08-07', '2018-08-08', '2018-08-09', '2018-08-10', '2018-08-11', '2018-08-12', '2018-08-13', '2018-08-14', '2018-08-15', '2018-08-16', '2018-08-17', '2018-08-18', '2018-08-19', '2018-08-20', '2018-08-21', '2018-08-22', '2018-08-23', '2018-08-24', '2018-08-25', '2018-08-26', '2018-08-27', '2018-08-28', '2018-08-29', '2018-08-30', '2018-08-31', '2018-09-01', '2018-09-02', '2018-09-03', '2018-09-04', '2018-09-05', '2018-09-06', '2018-09-07', '2018-09-08', '2018-09-09', '2018-09-10', '2018-09-11', '2018-09-12', '2018-09-13', '2018-09-14', '2018-09-15', '2018-09-16', '2018-09-17', '2018-09-18', '2018-09-19', '2018-09-20', '2018-09-21', '2018-09-22', '2018-09-23', '2018-09-24', '2018-09-25', '2018-09-26', '2018-09-27', '2018-09-28', '2018-09-29', '2018-09-30', '2018-10-01', '2018-10-02', '2018-10-03', '2018-10-04', '2018-10-05', '2018-10-06', '2018-10-07', '2018-10-08', '2018-10-09', '2018-10-10', '2018-10-11', '2018-10-12', '2018-10-13', '2018-10-14', '2018-10-15', '2018-10-16', '2018-10-17', '2018-10-18', '2018-10-19', '2018-10-20', '2018-10-21', '2018-10-22', '2018-10-23', '2018-10-24', '2018-10-25', '2018-10-26', '2018-10-27', '2018-10-28', '2018-10-29', '2018-10-30', '2018-10-31', '2018-11-01', '2018-11-02', '2018-11-03', '2018-11-04', '2018-11-05', '2018-11-06', '2018-11-07', '2018-11-08', '2018-11-09', '2018-11-10', '2018-11-11', '2018-11-12', '2018-11-13', '2018-11-14', '2018-11-15', '2018-11-16', '2018-11-17', '2018-11-18', '2018-11-19', '2018-11-20', '2018-11-21', '2018-11-22', '2018-11-23', '2018-11-24', '2018-11-25', '2018-11-26', '2018-11-27', '2018-11-28']
freq_2 = [85, 109, 134, 165, 125, 20, 10, 78, 107, 198, 105, 347, 66, 268, 357, 252, 45, 427, 13, 10, 1, 545, 286, 223, 18, 22, 15, 109, 83, 55, 276, 29, 189, 93, 25, 30, 50, 14, 36, 91, 77, 18, 40, 84, 50, 104, 274, 269, 657, 31, 200, 145, 34, 90, 50, 259, 42, 25, 67, 177, 25, 40, 82, 238, 53, 108, 276, 160, 126, 71, 13, 13, 152, 57, 161, 13, 51, 232, 154, 205, 22, 248, 202, 16, 78, 179, 12, 44, 205, 126, 56, 323, 270, 260, 426, 134, 87, 391, 133, 241, 399, 112, 368, 361, 199, 51, 55, 115, 624, 301, 194, 370, 63, 243, 302, 96, 134, 154, 74, 42, 97, 111, 132, 69, 54, 127, 236, 563, 181, 139, 49, 20, 45, 33, 130, 99, 34, 62, 96, 85, 122, 113, 165, 69, 87, 66, 826, 53, 102, 52, 105, 31, 47, 58, 218, 49, 70, 70, 74, 51, 33, 43, 40, 66, 184, 75, 118, 72, 78, 40, 455, 153, 33]
fig, ax = plt.subplots()
ax.plot(date_1, freq_1, c='blue')
ax.plot(date_2, freq_2, c='red')
plt.title("Date and frequency")
plt.ylabel("Frequency")
ax.get_xaxis().set_visible(False)
fig.autofmt_xdate()
plt.show()
Commenting out the first or second plot produces no issues, as shown:
But when trying to plot both at the same time, I get weird straight lines in my plot:
Plotting the second plot first gives
What is happening here and what's the most beginner friendly way to correct it?