Question: I need to visualize different indices as a heatmap or image. The goal is to plot hours on the y-axis, dates on the x-axis, and intensity values for each day. The attached figure illustrates the desired output:  I aim to create a figure using pcolormesh, pcolor, imshow, or Seaborn's heatmap. For context, KP > 40 indicates a storm, and DST < -30 also indicates a storm. An important date in the data is 2020/09/01, which corresponds to an earthquake. Here's the approach I've tried so far: X, Y = np.meshgrid(sw_indices.index.day, sw_indices.index.hour) from scipy.interpolate import griddata Z = griddata((sw_indices.index.day, sw_indices.index.hour), sw_indices.kp, (X, Y), method="nearest") fig, ax = plt.subplots() ax.pcolormesh(X, Y, Z)  Context The data being visualized in the described scenario is time series data concerning space weather indices, which track various environmental and astronomical measurements over time. The specific indices mentioned are:  kp: A planetary geomagnetic activity index, which measures geomagnetic storms. KP values above 40 typically indicate significant geomagnetic activity or storms. dst: Another geomagnetic index, where values below -30 indicate geomagnetic storms. ssn: Sunspot number, which is an index of the number of sunspots and groups of sunspots present on the surface of the sun. f10.7: The solar radio flux at 10.7 cm (2800 MHz), which is a measurement of the solar emissions in the microwave range, and it's often used as a proxy for solar activity.  The visualization aims to present space weather conditions by plotting KP index values across different hours and days. In this heatmap, the KP index is used as an indicator of geomagnetic activity, with higher values signifying more intense geomagnetic storms. By setting up the axes with dates on the x-axis and hours on the y-axis, and by mapping KP index values to color intensity, the visualization provides an insightful look into how geomagnetic conditions fluctuate over time. This approach allows for easy identification of critical events, such as storms, by observing changes in color intensity across the grid. The intended visualization method, such as using pcolormesh, pcolor, imshow, or Seaborn's heatmap, is apt for this kind of data as they can effectively show variations across two dimensions with color coding to represent the third dimension (intensity or magnitude of the indices). Other indices like dst, ssn, and f10.7 could potentially be visualized in a similar manner to track different types of environmental conditions or solar activity. Data Here's the link to the full data file: Google Drive Link Here are excerpts from the data: ,year,doy,hr,kp,ssn,dst,f10_7 2020-08-02 00:00:00,YEAR,DOY,HR,1,2,3,4.0 2020-08-02 01:00:00,2020,215,0,3,15,18,74.9 2020-08-02 02:00:00,2020,215,1,3,15,16,74.9 2020-08-02 03:00:00,2020,215,2,3,15,10,74.9 2020-08-02 04:00:00,2020,215,3,7,15,7,74.9 2020-08-02 05:00:00,2020,215,4,7,15,6,74.9 2020-08-02 06:00:00,2020,215,5,7,15,11,74.9 2020-08-02 07:00:00,2020,215,6,10,15,17,74.9 2020-08-02 08:00:00,2020,215,7,10,15,14,74.9 2020-08-02 09:00:00,2020,215,8,10,15,19,74.9 2020-08-02 10:00:00,2020,215,9,27,15,22,74.9 2020-08-02 11:00:00,2020,215,10,27,15,21,74.9 2020-08-02 12:00:00,2020,215,11,27,15,12,74.9 2020-08-02 13:00:00,2020,215,12,33,15,-2,74.9 2020-08-02 14:00:00,2020,215,13,33,15,-14,74.9 2020-08-02 15:00:00,2020,215,14,33,15,-12,74.9 2020-08-02 16:00:00,2020,215,15,30,15,-14,74.9 2020-08-02 17:00:00,2020,215,16,30,15,-14,74.9 2020-08-02 18:00:00,2020,215,17,30,15,-7,74.9 2020-08-02 19:00:00,2020,215,18,20,15,0,74.9 2020-08-02 20:00:00,2020,215,19,20,15,3,74.9 2020-08-02 21:00:00,2020,215,20,20,15,9,74.9 2020-08-02 22:00:00,2020,215,21,30,15,-3,74.9 2020-08-02 23:00:00,2020,215,22,30,15,-8,74.9 2020-08-03 00:00:00,2020,215,23,30,15,-5,74.9 2020-08-03 01:00:00,2020,216,0,33,11,-2,74.8 2020-08-03 02:00:00,2020,216,1,33,11,-1,74.8 2020-08-03 03:00:00,2020,216,2,33,11,-2,74.8 2020-08-03 04:00:00,2020,216,3,33,11,-19,74.8 2020-08-03 05:00:00,2020,216,4,33,11,-17,74.8 2020-08-03 06:00:00,2020,216,5,33,11,-16,74.8 2020-08-03 07:00:00,2020,216,6,30,11,-22,74.8 2020-08-03 08:00:00,2020,216,7,30,11,-20,74.8 2020-08-03 09:00:00,2020,216,8,30,11,-28,74.8 2020-08-03 10:00:00,2020,216,9,27,11,-30,74.8 2020-08-03 11:00:00,2020,216,10,27,11,-18,74.8 2020-08-03 12:00:00,2020,216,11,27,11,-12,74.8 2020-08-03 13:00:00,2020,216,12,23,11,-7,74.8 2020-08-03 14:00:00,2020,216,13,23,11,-7,74.8 2020-08-03 15:00:00,2020,216,14,23,11,-9,74.8 2020-08-03 16:00:00,2020,216,15,33,11,-8,74.8 2020-08-03 17:00:00,2020,216,16,33,11,-3,74.8 2020-08-03 18:00:00,2020,216,17,33,11,-7,74.8 2020-08-03 19:00:00,2020,216,18,30,11,-13,74.8 2020-08-03 20:00:00,2020,216,19,30,11,-16,74.8 2020-08-03 21:00:00,2020,216,20,30,11,-16,74.8 2020-08-03 22:00:00,2020,216,21,33,11,-15,74.8 2020-08-03 23:00:00,2020,216,22,33,11,-21,74.8 2020-08-04 00:00:00,2020,216,23,33,11,-18,74.8 2020-08-04 01:00:00,2020,217,0,20,11,-14,75.1 2020-08-04 02:00:00,2020,217,1,20,11,-13,75.1 2020-08-04 03:00:00,2020,217,2,20,11,-18,75.1 2020-08-04 04:00:00,2020,217,3,33,11,-21,75.1 2020-08-04 05:00:00,2020,217,4,33,11,-20,75.1 2020-08-04 06:00:00,2020,217,5,33,11,-15,75.1 2020-08-04 07:00:00,2020,217,6,13,11,-13,75.1 2020-08-04 08:00:00,2020,217,7,13,11,-12,75.1 2020-08-04 09:00:00,2020,217,8,13,11,-11,75.1 2020-08-04 10:00:00,2020,217,9,17,11,-10,75.1 2020-08-04 11:00:00,2020,217,10,17,11,-9,75.1 2020-08-04 12:00:00,2020,217,11,17,11,-5,75.1 2020-08-04 13:00:00,2020,217,12,13,11,-5,75.1 2020-08-04 14:00:00,2020,217,13,13,11,-5,75.1 2020-08-04 15:00:00,2020,217,14,13,11,-5,75.1 2020-08-04 16:00:00,2020,217,15,13,11,-2,75.1 2020-08-04 17:00:00,2020,217,16,13,11,-1,75.1 2020-08-04 18:00:00,2020,217,17,13,11,-3,75.1 2020-08-04 19:00:00,2020,217,18,13,11,-3,75.1 2020-08-04 20:00:00,2020,217,19,13,11,-6,75.1 2020-08-04 21:00:00,2020,217,20,13,11,-10,75.1 2020-08-04 22:00:00,2020,217,21,17,11,-8,75.1 2020-08-04 23:00:00,2020,217,22,17,11,-11,75.1 2020-08-05 00:00:00,2020,217,23,17,11,-13,75.1 2020-08-05 01:00:00,2020,218,0,17,12,-11,75.6 2020-08-05 02:00:00,2020,218,1,17,12,-8,75.6 2020-08-05 03:00:00,2020,218,2,17,12,-11,75.6 2020-08-05 04:00:00,2020,218,3,13,12,-12,75.6 2020-08-05 05:00:00,2020,218,4,13,12,-11,75.6 2020-08-05 06:00:00,2020,218,5,13,12,-14,75.6 2020-08-05 07:00:00,2020,218,6,10,12,-14,75.6 2020-08-05 08:00:00,2020,218,7,10,12,-12,75.6 2020-08-05 09:00:00,2020,218,8,10,12,-11,75.6 2020-08-05 10:00:00,2020,218,9,7,12,-11,75.6 2020-08-05 11:00:00,2020,218,10,7,12,-11,75.6 2020-08-05 12:00:00,2020,218,11,7,12,-9,75.6 2020-08-05 13:00:00,2020,218,12,7,12,-7,75.6 2020-08-05 14:00:00,2020,218,13,7,12,-7,75.6 2020-08-05 15:00:00,2020,218,14,7,12,-4,75.6 2020-08-05 16:00:00,2020,218,15,10,12,-2,75.6 2020-08-05 17:00:00,2020,218,16,10,12,-3,75.6 2020-08-05 18:00:00,2020,218,17,10,12,-5,75.6 2020-08-05 19:00:00,2020,218,18,23,12,-4,75.6 2020-08-05 20:00:00,2020,218,19,23,12,-7,75.6 2020-08-05 21:00:00,2020,218,20,23,12,-5,75.6 2020-08-05 22:00:00,2020,218,21,13,12,-7,75.6 2020-08-05 23:00:00,2020,218,22,13,12,-12,75.6 2020-08-06 00:00:00,2020,218,23,13,12,-15,75.6 2020-08-06 01:00:00,2020,219,0,7,14,-16,75.1 2020-08-06 02:00:00,2020,219,1,7,14,-16,75.1 2020-08-06 03:00:00,2020,219,2,7,14,-13,75.1 2020-08-06 04:00:00,2020,219,3,13,14,-7,75.1 2020-08-06 05:00:00,2020,219,4,13,14,-2,75.1 2020-08-06 06:00:00,2020,219,5,13,14,1,75.1 2020-08-06 07:00:00,2020,219,6,3,14,1,75.1 2020-08-06 08:00:00,2020,219,7,3,14,0,75.1 2020-08-06 09:00:00,2020,219,8,3,14,-2,75.1 2020-08-06 10:00:00,2020,219,9,7,14,-5,75.1 2020-08-06 11:00:00,2020,219,10,7,14,-3,75.1 2020-08-06 12:00:00,2020,219,11,7,14,-1,75.1 2020-08-06 13:00:00,2020,219,12,17,14,-3,75.1 2020-08-06 14:00:00,2020,219,13,17,14,-8,75.1 2020-08-06 15:00:00,2020,219,14,17,14,-6,75.1 2020-08-06 16:00:00,2020,219,15,13,14,-6,75.1 2020-08-06 17:00:00,2020,219,16,13,14,-8,75.1 2020-08-06 18:00:00,2020,219,17,13,14,-9,75.1 2020-08-06 19:00:00,2020,219,18,7,14,-12,75.1 2020-08-06 20:00:00,2020,219,19,7,14,-10,75.1 2020-08-06 21:00:00,2020,219,20,7,14,-4,75.1 2020-08-06 22:00:00,2020,219,21,20,14,-7,75.1 2020-08-06 23:00:00,2020,219,22,20,14,-14,75.1 2020-08-07 00:00:00,2020,219,23,20,14,-16,75.1 2020-08-07 01:00:00,2020,220,0,17,17,-13,76.0 2020-08-07 02:00:00,2020,220,1,17,17,-14,76.0 2020-08-07 03:00:00,2020,220,2,17,17,-14,76.0 2020-08-07 04:00:00,2020,220,3,10,17,-13,76.0 2020-08-07 05:00:00,2020,220,4,10,17,-13,76.0 2020-08-07 06:00:00,2020,220,5,10,17,-11,76.0 2020-08-07 07:00:00,2020,220,6,0,17,-5,76.0 2020-08-07 08:00:00,2020,220,7,0,17,-3,76.0 2020-08-07 09:00:00,2020,220,8,0,17,-2,76.0 2020-08-07 10:00:00,2020,220,9,3,17,-2,76.0 2020-08-07 11:00:00,2020,220,10,3,17,-2,76.0 2020-08-07 12:00:00,2020,220,11,3,17,2,76.0 2020-08-07 13:00:00,2020,220,12,3,17,4,76.0 2020-08-07 14:00:00,2020,220,13,3,17,5,76.0 2020-08-07 15:00:00,2020,220,14,3,17,4,76.0 2020-08-07 16:00:00,2020,220,15,3,17,3,76.0 2020-08-07 17:00:00,2020,220,16,3,17,0,76.0 2020-08-07 18:00:00,2020,220,17,3,17,0,76.0 2020-08-07 19:00:00,2020,220,18,7,17,1,76.0 2020-08-07 20:00:00,2020,220,19,7,17,1,76.0 2020-08-07 21:00:00,2020,220,20,7,17,1,76.0 2020-08-07 22:00:00,2020,220,21,13,17,-2,76.0 2020-08-07 23:00:00,2020,220,22,13,17,-3,76.0 2020-08-08 00:00:00,2020,220,23,13,17,-1,76.0 2020-08-08 01:00:00,2020,221,0,20,12,-3,76.8 2020-08-08 02:00:00,2020,221,1,20,12,-6,76.8 2020-08-08 03:00:00,2020,221,2,20,12,-5,76.8 2020-08-08 04:00:00,2020,221,3,17,12,-4,76.8 2020-08-08 05:00:00,2020,221,4,17,12,-4,76.8 2020-08-08 06:00:00,2020,221,5,17,12,-5,76.8 2020-08-08 07:00:00,2020,221,6,13,12,-8,76.8 2020-08-08 08:00:00,2020,221,7,13,12,-10,76.8 2020-08-08 09:00:00,2020,221,8,13,12,-11,76.8 2020-08-08 10:00:00,2020,221,9,10,12,-7,76.8 2020-08-08 11:00:00,2020,221,10,10,12,-5,76.8 2020-08-08 12:00:00,2020,221,11,10,12,-4,76.8 2020-08-08 13:00:00,2020,221,12,13,12,-7,76.8 2020-08-08 14:00:00,2020,221,13,13,12,-8,76.8 2020-08-08 15:00:00,2020,221,14,13,12,-8,76.8 2020-08-08 16:00:00,2020,221,15,10,12,-10,76.8 2020-08-08 17:00:00,2020,221,16,10,12,-12,76.8 2020-08-08 18:00:00,2020,221,17,10,12,-12,76.8 2020-08-08 19:00:00,2020,221,18,7,12,-12,76.8 2020-08-08 20:00:00,2020,221,19,7,12,-10,76.8 2020-08-08 21:00:00,2020,221,20,7,12,-7,76.8 2020-08-08 22:00:00,2020,221,21,3,12,-2,76.8 2020-08-08 23:00:00,2020,221,22,3,12,0,76.8 2020-08-09 00:00:00,2020,221,23,3,12,-2,76.8 2020-08-09 01:00:00,2020,222,0,0,13,-4,76.0 2020-08-09 02:00:00,2020,222,1,0,13,-7,76.0 2020-08-09 03:00:00,2020,222,2,0,13,-8,76.0 2020-08-09 04:00:00,2020,222,3,3,13,-7,76.0 2020-08-09 05:00:00,2020,222,4,3,13,-7,76.0 2020-08-09 06:00:00,2020,222,5,3,13,-5,76.0 2020-08-09 07:00:00,2020,222,6,3,13,-2,76.0 2020-08-09 08:00:00,2020,222,7,3,13,-1,76.0 2020-08-09 09:00:00,2020,222,8,3,13,-2,76.0 2020-08-09 10:00:00,2020,222,9,7,13,-7,76.0 2020-08-09 11:00:00,2020,222,10,7,13,-8,76.0 2020-08-09 12:00:00,2020,222,11,7,13,-8,76.0 2020-08-09 13:00:00,2020,222,12,3,13,-8,76.0 2020-08-09 14:00:00,2020,222,13,3,13,-8,76.0 2020-08-09 15:00:00,2020,222,14,3,13,-6,76.0 2020-08-09 16:00:00,2020,222,15,3,13,-3,76.0 2020-08-09 17:00:00,2020,222,16,3,13,-4,76.0 2020-08-09 18:00:00,2020,222,17,3,13,-5,76.0 2020-08-09 19:00:00,2020,222,18,3,13,-4,76.0 2020-08-09 20:00:00,2020,222,19,3,13,0,76.0 2020-08-09 21:00:00,2020,222,20,3,13,4,76.0 2020-08-09 22:00:00,2020,222,21,7,13,5,76.0 2020-08-09 23:00:00,2020,222,22,7,13,5,76.0 2020-08-10 00:00:00,2020,222,23,7,13,6,76.0 2020-08-10 01:00:00,2020,223,0,3,13,4,76.2 2020-08-10 02:00:00,2020,223,1,3,13,4,76.2 2020-08-10 03:00:00,2020,223,2,3,13,6,76.2 2020-08-10 04:00:00,2020,223,3,3,13,5,76.2 2020-08-10 05:00:00,2020,223,4,3,13,2,76.2 2020-08-10 06:00:00,2020,223,5,3,13,0,76.2 2020-08-10 07:00:00,2020,223,6,3,13,-3,76.2 2020-08-10 08:00:00,2020,223,7,3,13,-5,76.2 2020-08-10 09:00:00,2020,223,8,3,13,-6,76.2 2020-08-10 10:00:00,2020,223,9,3,13,-7,76.2 2020-08-10 11:00:00,2020,223,10,3,13,-5,76.2 2020-08-10 12:00:00,2020,223,11,3,13,-4,76.2 2020-08-10 13:00:00,2020,223,12,0,13,-5,76.2 2020-08-10 14:00:00,2020,223,13,0,13,-4,76.2 2020-08-10 15:00:00,2020,223,14,0,13,0,76.2 2020-08-10 16:00:00,2020,223,15,7,13,1,76.2 2020-08-10 17:00:00,2020,223,16,7,13,-1,76.2 2020-08-10 18:00:00,2020,223,17,7,13,-1,76.2 2020-08-10 19:00:00,2020,223,18,3,13,0,76.2 2020-08-10 20:00:00,2020,223,19,3,13,3,76.2 2020-08-10 21:00:00,2020,223,20,3,13,4,76.2 2020-08-10 22:00:00,2020,223,21,7,13,3,76.2 2020-08-10 23:00:00,2020,223,22,7,13,1,76.2 2020-08-11 00:00:00,2020,223,23,7,13,-1,76.2 2020-08-11 01:00:00,2020,224,0,10,12,2,75.4 2020-08-11 02:00:00,2020,224,1,10,12,1,75.4 2020-08-11 03:00:00,2020,224,2,10,12,-3,75.4 2020-08-11 04:00:00,2020,224,3,7,12,-6,75.4 2020-08-11 05:00:00,2020,224,4,7,12,-6,75.4 2020-08-11 06:00:00,2020,224,5,7,12,-5,75.4 2020-08-11 07:00:00,2020,224,6,3,12,-4,75.4 2020-08-11 08:00:00,2020,224,7,3,12,-3,75.4 2020-08-11 09:00:00,2020,224,8,3,12,-4,75.4 2020-08-11 10:00:00,2020,224,9,3,12,-3,75.4 2020-08-11 11:00:00,2020,224,10,3,12,-2,75.4 2020-08-11 12:00:00,2020,224,11,3,12,-3,75.4 2020-08-11 13:00:00,2020,224,12,3,12,-3,75.4 2020-08-11 14:00:00,2020,224,13,3,12,0,75.4 2020-08-11 15:00:00,2020,224,14,3,12,1,75.4 2020-08-11 16:00:00,2020,224,15,0,12,2,75.4 2020-08-11 17:00:00,2020,224,16,0,12,1,75.4 2020-08-11 18:00:00,2020,224,17,0,12,1,75.4 2020-08-11 19:00:00,2020,224,18,0,12,5,75.4 2020-08-11 20:00:00,2020,224,19,0,12,6,75.4 2020-08-11 21:00:00,2020,224,20,0,12,5,75.4 2020-08-11 22:00:00,2020,224,21,3,12,4,75.4 2020-08-11 23:00:00,2020,224,22,3,12,7,75.4 2020-08-12 00:00:00,2020,224,23,3,12,10,75.4 2020-08-12 01:00:00,2020,225,0,3,17,10,75.1 2020-08-12 02:00:00,2020,225,1,3,17,10,75.1 2020-08-12 03:00:00,2020,225,2,3,17,12,75.1 2020-08-12 04:00:00,2020,225,3,13,17,9,75.1 2020-08-12 05:00:00,2020,225,4,13,17,5,75.1 2020-08-12 06:00:00,2020,225,5,13,17,3,75.1 2020-08-12 07:00:00,2020,225,6,10,17,2,75.1 2020-08-12 08:00:00,2020,225,7,10,17,2,75.1 2020-08-12 09:00:00,2020,225,8,10,17,0,75.1 2020-08-12 10:00:00,2020,225,9,7,17,1,75.1 2020-08-12 11:00:00,2020,225,10,7,17,2,75.1 2020-08-12 12:00:00,2020,225,11,7,17,3,75.1 2020-08-12 13:00:00,2020,225,12,10,17,3,75.1 2020-08-12 14:00:00,2020,225,13,10,17,6,75.1 2020-08-12 15:00:00,2020,225,14,10,17,7,75.1 2020-08-12 16:00:00,2020,225,15,7,17,8,75.1 2020-08-12 17:00:00,2020,225,16,7,17,8,75.1 2020-08-12 18:00:00,2020,225,17,7,17,7,75.1 2020-08-12 19:00:00,2020,225,18,7,17,5,75.1 2020-08-12 20:00:00,2020,225,19,7,17,4,75.1 2020-08-12 21:00:00,2020,225,20,7,17,6,75.1 2020-08-12 22:00:00,2020,225,21,3,17,7,75.1 2020-08-12 23:00:00,2020,225,22,3,17,5,75.1 2020-08-13 00:00:00,2020,225,23,3,17,2,75.1 2020-08-13 01:00:00,2020,226,0,17,10,1,74.2 2020-08-13 02:00:00,2020,226,1,17,10,0,74.2 2020-08-13 03:00:00,2020,226,2,17,10,0,74.2 2020-08-13 04:00:00,2020,226,3,7,10,-2,74.2 2020-08-13 05:00:00,2020,226,4,7,10,-1,74.2 2020-08-13 06:00:00,2020,226,5,7,10,2,74.2 2020-08-13 07:00:00,2020,226,6,3,10,4,74.2 2020-08-13 08:00:00,2020,226,7,3,10,7,74.2 2020-08-13 09:00:00,2020,226,8,3,10,6,74.2 2020-08-13 10:00:00,2020,226,9,3,10,5,74.2 2020-08-13 11:00:00,2020,226,10,3,10,4,74.2 2020-08-13 12:00:00,2020,226,11,3,10,2,74.2 2020-08-13 13:00:00,2020,226,12,13,10,2,74.2 2020-08-13 14:00:00,2020,226,13,13,10,2,74.2 2020-08-13 15:00:00,2020,226,14,13,10,3,74.2 2020-08-13 16:00:00,2020,226,15,3,10,2,74.2 2020-08-13 17:00:00,2020,226,16,3,10,3,74.2 2020-08-13 18:00:00,2020,226,17,3,10,1,74.2 2020-08-13 19:00:00,2020,226,18,3,10,-1,74.2 2020-08-13 20:00:00,2020,226,19,3,10,-1,74.2 2020-08-13 21:00:00,2020,226,20,3,10,2,74.2 2020-08-13 22:00:00,2020,226,21,13,10,-1,74.2 2020-08-13 23:00:00,2020,226,22,13,10,-5,74.2 2020-08-14 00:00:00,2020,226,23,13,10,-5,74.2 2020-08-14 01:00:00,2020,227,0,10,5,-2,72.6 2020-08-14 02:00:00,2020,227,1,10,5,1,72.6 2020-08-14 03:00:00,2020,227,2,10,5,6,72.6 2020-08-14 04:00:00,2020,227,3,17,5,4,72.6 2020-08-14 05:00:00,2020,227,4,17,5,1,72.6 2020-08-14 06:00:00,2020,227,5,17,5,3,72.6 2020-08-14 07:00:00,2020,227,6,3,5,3,72.6 2020-08-14 08:00:00,2020,227,7,3,5,2,72.6 2020-08-14 09:00:00,2020,227,8,3,5,3,72.6 2020-08-14 10:00:00,2020,227,9,3,5,6,72.6 2020-08-14 11:00:00,2020,227,10,3,5,8,72.6 2020-08-14 12:00:00,2020,227,11,3,5,7,72.6 2020-08-14 13:00:00,2020,227,12,7,5,5,72.6 2020-08-14 14:00:00,2020,227,13,7,5,6,72.6 2020-08-14 15:00:00,2020,227,14,7,5,6,72.6 2020-08-14 16:00:00,2020,227,15,3,5,7,72.6 2020-08-14 17:00:00,2020,227,16,3,5,6,72.6 2020-08-14 18:00:00,2020,227,17,3,5,3,72.6 2020-08-14 19:00:00,2020,227,18,7,5,-1,72.6 2020-08-14 20:00:00,2020,227,19,7,5,-5,72.6 2020-08-14 21:00:00,2020,227,20,7,5,-8,72.6 2020-08-14 22:00:00,2020,227,21,7,5,-9,72.6 2020-08-14 23:00:00,2020,227,22,7,5,-9,72.6 2020-08-15 00:00:00,2020,227,23,7,5,-11,72.6 2020-08-15 01:00:00,2020,228,0,0,0,-10,72.4 2020-08-15 02:00:00,2020,228,1,0,0,-5,72.4 2020-09-03 22:00:00,2020,247,21,17,0,-15,71.2 2020-09-03 23:00:00,2020,247,22,17,0,-17,71.2 2020-09-04 00:00:00,2020,247,23,17,0,-21,71.2 2020-09-04 01:00:00,2020,248,0,27,0,-22,70.8 2020-09-04 02:00:00,2020,248,1,27,0,-23,70.8 2020-09-04 03:00:00,2020,248,2,27,0,-19,70.8 2020-09-04 04:00:00,2020,248,3,13,0,-16,70.8 2020-09-04 05:00:00,2020,248,4,13,0,-14,70.8 2020-09-04 06:00:00,2020,248,5,13,0,-15,70.8 2020-09-04 07:00:00,2020,248,6,13,0,-18,70.8 2020-09-04 08:00:00,2020,248,7,13,0,-18,70.8 2020-09-04 09:00:00,2020,248,8,13,0,-15,70.8 2020-09-04 10:00:00,2020,248,9,20,0,-11,70.8 2020-09-04 11:00:00,2020,248,10,20,0,-18,70.8 2020-09-04 12:00:00,2020,248,11,20,0,-19,70.8 2020-09-04 13:00:00,2020,248,12,20,0,-18,70.8 2020-09-04 14:00:00,2020,248,13,20,0,-22,70.8 2020-09-04 15:00:00,2020,248,14,20,0,-21,70.8 2020-09-04 16:00:00,2020,248,15,17,0,-26,70.8 2020-09-04 17:00:00,2020,248,16,17,0,-27,70.8 2020-09-04 18:00:00,2020,248,17,17,0,-25,70.8 2020-09-04 19:00:00,2020,248,18,23,0,-22,70.8 2020-09-04 20:00:00,2020,248,19,23,0,-20,70.8 2020-09-04 21:00:00,2020,248,20,23,0,-24,70.8 2020-09-04 22:00:00,2020,248,21,3,0,-22,70.8 2020-09-04 23:00:00,2020,248,22,3,0,-21,70.8 2020-09-05 00:00:00,2020,248,23,3,0,-21,70.8 2020-09-05 01:00:00,2020,249,0,17,0,-21,70.3 2020-09-05 02:00:00,2020,249,1,17,0,-22,70.3 2020-09-05 03:00:00,2020,249,2,17,0,-23,70.3 2020-09-05 04:00:00,2020,249,3,13,0,-22,70.3 2020-09-05 05:00:00,2020,249,4,13,0,-19,70.3 2020-09-05 06:00:00,2020,249,5,13,0,-16,70.3 2020-09-05 07:00:00,2020,249,6,17,0,-15,70.3 2020-09-05 08:00:00,2020,249,7,17,0,-15,70.3 2020-09-05 09:00:00,2020,249,8,17,0,-21,70.3 2020-09-05 10:00:00,2020,249,9,20,0,-23,70.3 2020-09-05 11:00:00,2020,249,10,20,0,-22,70.3 2020-09-05 12:00:00,2020,249,11,20,0,-11,70.3 2020-09-05 13:00:00,2020,249,12,17,0,-7,70.3 2020-09-05 14:00:00,2020,249,13,17,0,-7,70.3 2020-09-05 15:00:00,2020,249,14,17,0,-7,70.3 2020-09-05 16:00:00,2020,249,15,3,0,-8,70.3 2020-09-05 17:00:00,2020,249,16,3,0,-9,70.3 2020-09-05 18:00:00,2020,249,17,3,0,-7,70.3 2020-09-05 19:00:00,2020,249,18,10,0,-8,70.3 2020-09-05 20:00:00,2020,249,19,10,0,-6,70.3 2020-09-05 21:00:00,2020,249,20,10,0,-6,70.3 2020-09-05 22:00:00,2020,249,21,10,0,-8,70.3 2020-09-05 23:00:00,2020,249,22,10,0,-9,70.3 2020-09-06 00:00:00,2020,249,23,10,0,-14,70.3 2020-09-06 01:00:00,2020,250,0,20,0,-18,70.5 2020-09-06 02:00:00,2020,250,1,20,0,-21,70.5 2020-09-06 03:00:00,2020,250,2,20,0,-16,70.5 2020-09-06 04:00:00,2020,250,3,10,0,-12,70.5 2020-09-06 05:00:00,2020,250,4,10,0,-10,70.5 2020-09-06 06:00:00,2020,250,5,10,0,-11,70.5 2020-09-06 07:00:00,2020,250,6,3,0,-8,70.5 2020-09-06 08:00:00,2020,250,7,3,0,-5,70.5 2020-09-06 09:00:00,2020,250,8,3,0,-7,70.5 2020-09-06 10:00:00,2020,250,9,10,0,-6,70.5 2020-09-06 11:00:00,2020,250,10,10,0,-6,70.5 2020-09-06 12:00:00,2020,250,11,10,0,-9,70.5 2020-09-06 13:00:00,2020,250,12,10,0,-9,70.5 2020-09-06 14:00:00,2020,250,13,10,0,-7,70.5 2020-09-06 15:00:00,2020,250,14,10,0,-6,70.5 2020-09-06 16:00:00,2020,250,15,3,0,-7,70.5 2020-09-06 17:00:00,2020,250,16,3,0,-7,70.5 2020-09-06 18:00:00,2020,250,17,3,0,-6,70.5 2020-09-06 19:00:00,2020,250,18,7,0,-5,70.5 2020-09-06 20:00:00,2020,250,19,7,0,-6,70.5 2020-09-06 21:00:00,2020,250,20,7,0,-9,70.5 2020-09-06 22:00:00,2020,250,21,17,0,-15,70.5 2020-09-06 23:00:00,2020,250,22,17,0,-20,70.5 2020-09-07 00:00:00,2020,250,23,17,0,-21,70.5 2020-09-07 01:00:00,2020,251,0,10,0,-21,71.3 2020-09-07 02:00:00,2020,251,1,10,0,-16,71.3 2020-09-07 03:00:00,2020,251,2,10,0,-13,71.3 2020-09-07 04:00:00,2020,251,3,13,0,-11,71.3 2020-09-07 05:00:00,2020,251,4,13,0,-14,71.3 2020-09-07 06:00:00,2020,251,5,13,0,-17,71.3 2020-09-07 07:00:00,2020,251,6,13,0,-14,71.3 2020-09-07 08:00:00,2020,251,7,13,0,-10,71.3 2020-09-07 09:00:00,2020,251,8,13,0,-11,71.3 2020-09-07 10:00:00,2020,251,9,7,0,-11,71.3 2020-09-07 11:00:00,2020,251,10,7,0,-13,71.3 2020-09-07 12:00:00,2020,251,11,7,0,-14,71.3 2020-09-07 13:00:00,2020,251,12,7,0,-15,71.3 2020-09-07 14:00:00,2020,251,13,7,0,-12,71.3 2020-09-07 15:00:00,2020,251,14,7,0,-12,71.3 2020-09-07 16:00:00,2020,251,15,10,0,-10,71.3 2020-09-07 17:00:00,2020,251,16,10,0,-13,71.3 2020-09-07 18:00:00,2020,251,17,10,0,-12,71.3 2020-09-07 19:00:00,2020,251,18,3,0,-9,71.3 2020-09-07 20:00:00,2020,251,19,3,0,-8,71.3 2020-09-07 21:00:00,2020,251,20,3,0,-10,71.3 2020-09-07 22:00:00,2020,251,21,0,0,-14,71.3 2020-09-07 23:00:00,2020,251,22,0,0,-16,71.3 2020-09-08 00:00:00,2020,251,23,0,0,-16,71.3 2020-09-08 01:00:00,2020,252,0,7,0,-12,70.9 2020-09-08 02:00:00,2020,252,1,7,0,-12,70.9 2020-09-08 03:00:00,2020,252,2,7,0,-13,70.9 2020-09-08 04:00:00,2020,252,3,3,0,-12,70.9 2020-09-08 05:00:00,2020,252,4,3,0,-12,70.9 2020-09-08 06:00:00,2020,252,5,3,0,-12,70.9 2020-09-08 07:00:00,2020,252,6,10,0,-9,70.9 2020-09-08 08:00:00,2020,252,7,10,0,-6,70.9 2020-09-08 09:00:00,2020,252,8,10,0,-6,70.9 2020-09-08 10:00:00,2020,252,9,10,0,-1,70.9 2020-09-08 11:00:00,2020,252,10,10,0,2,70.9 2020-09-08 12:00:00,2020,252,11,10,0,1,70.9 2020-09-08 13:00:00,2020,252,12,7,0,2,70.9 2020-09-08 14:00:00,2020,252,13,7,0,3,70.9 2020-09-08 15:00:00,2020,252,14,7,0,-1,70.9 2020-09-08 16:00:00,2020,252,15,13,0,-6,70.9 2020-09-08 17:00:00,2020,252,16,13,0,-7,70.9 2020-09-08 18:00:00,2020,252,17,13,0,-9,70.9 2020-09-08 19:00:00,2020,252,18,10,0,-7,70.9 2020-09-08 20:00:00,2020,252,19,10,0,-5,70.9 2020-09-08 21:00:00,2020,252,20,10,0,-3,70.9 2020-09-08 22:00:00,2020,252,21,0,0,-2,70.9 2020-09-08 23:00:00,2020,252,22,0,0,-2,70.9 2020-09-09 00:00:00,2020,252,23,0,0,-2,70.9 2020-09-09 01:00:00,2020,253,0,7,0,-3,70.7 2020-09-09 02:00:00,2020,253,1,7,0,-4,70.7 2020-09-09 03:00:00,2020,253,2,7,0,-4,70.7 2020-09-09 04:00:00,2020,253,3,0,0,-5,70.7 2020-09-09 05:00:00,2020,253,4,0,0,-5,70.7 2020-09-09 06:00:00,2020,253,5,0,0,-6,70.7 2020-09-09 07:00:00,2020,253,6,0,0,-2,70.7 2020-09-09 08:00:00,2020,253,7,0,0,0,70.7 2020-09-09 09:00:00,2020,253,8,0,0,0,70.7 2020-09-09 10:00:00,2020,253,9,0,0,1,70.7 2020-09-09 11:00:00,2020,253,10,0,0,2,70.7 2020-09-09 12:00:00,2020,253,11,0,0,1,70.7 2020-09-09 13:00:00,2020,253,12,0,0,1,70.7 2020-09-09 14:00:00,2020,253,13,0,0,0,70.7 2020-09-09 15:00:00,2020,253,14,0,0,-1,70.7 2020-09-09 16:00:00,2020,253,15,3,0,-2,70.7 2020-09-09 17:00:00,2020,253,16,3,0,-1,70.7 2020-09-09 18:00:00,2020,253,17,3,0,0,70.7 2020-09-09 19:00:00,2020,253,18,0,0,0,70.7 2020-09-09 20:00:00,2020,253,19,0,0,1,70.7 2020-09-09 21:00:00,2020,253,20,0,0,0,70.7 2020-09-09 22:00:00,2020,253,21,0,0,-1,70.7 2020-09-09 23:00:00,2020,253,22,0,0,1,70.7 2020-09-10 00:00:00,2020,253,23,0,0,1,70.7 2020-09-10 01:00:00,2020,254,0,0,0,0,70.2 2020-09-10 02:00:00,2020,254,1,0,0,0,70.2 2020-09-10 03:00:00,2020,254,2,0,0,0,70.2 2020-09-10 04:00:00,2020,254,3,0,0,-1,70.2 2020-09-10 05:00:00,2020,254,4,0,0,-1,70.2 2020-09-10 06:00:00,2020,254,5,0,0,-2,70.2 2020-09-10 07:00:00,2020,254,6,0,0,-3,70.2 2020-09-10 08:00:00,2020,254,7,0,0,-1,70.2 2020-09-10 09:00:00,2020,254,8,0,0,1,70.2 2020-09-10 10:00:00,2020,254,9,3,0,3,70.2 2020-09-10 11:00:00,2020,254,10,3,0,-1,70.2 2020-09-10 12:00:00,2020,254,11,3,0,1,70.2 2020-09-10 13:00:00,2020,254,12,3,0,2,70.2 2020-09-10 14:00:00,2020,254,13,3,0,4,70.2 2020-09-10 15:00:00,2020,254,14,3,0,3,70.2 2020-09-10 16:00:00,2020,254,15,3,0,2,70.2 2020-09-10 17:00:00,2020,254,16,3,0,2,70.2 2020-09-10 18:00:00,2020,254,17,3,0,4,70.2 2020-09-10 19:00:00,2020,254,18,10,0,3,70.2 2020-09-10 20:00:00,2020,254,19,10,0,1,70.2 2020-09-10 21:00:00,2020,254,20,10,0,1,70.2 2020-09-10 22:00:00,2020,254,21,3,0,4,70.2 2020-09-10 23:00:00,2020,254,22,3,0,4,70.2 2020-09-11 00:00:00,2020,254,23,3,0,2,70.2 2020-09-11 01:00:00,2020,255,0,0,0,2,69.6 2020-09-11 02:00:00,2020,255,1,0,0,4,69.6 2020-09-11 03:00:00,2020,255,2,0,0,3,69.6 2020-09-11 04:00:00,2020,255,3,0,0,4,69.6 2020-09-11 05:00:00,2020,255,4,0,0,2,69.6 2020-09-11 06:00:00,2020,255,5,0,0,2,69.6 2020-09-11 07:00:00,2020,255,6,3,0,2,69.6 2020-09-11 08:00:00,2020,255,7,3,0,2,69.6 2020-09-11 09:00:00,2020,255,8,3,0,-1,69.6 2020-09-11 10:00:00,2020,255,9,3,0,-2,69.6 2020-09-11 11:00:00,2020,255,10,3,0,-1,69.6 2020-09-11 12:00:00,2020,255,11,3,0,-2,69.6 2020-09-11 13:00:00,2020,255,12,0,0,-2,69.6 2020-09-11 14:00:00,2020,255,13,0,0,-1,69.6 2020-09-11 15:00:00,2020,255,14,0,0,-1,69.6 2020-09-11 16:00:00,2020,255,15,7,0,-1,69.6 2020-09-11 17:00:00,2020,255,16,7,0,0,69.6 2020-09-11 18:00:00,2020,255,17,7,0,-2,69.6 2020-09-11 19:00:00,2020,255,18,10,0,0,69.6 2020-09-11 20:00:00,2020,255,19,10,0,-1,69.6 2020-09-11 21:00:00,2020,255,20,10,0,-2,69.6 2020-09-11 22:00:00,2020,255,21,10,0,-6,69.6 2020-09-11 23:00:00,2020,255,22,10,0,-10,69.6 2020-09-12 00:00:00,2020,255,23,10,0,-11,69.6 2020-09-12 01:00:00,2020,256,0,13,0,-10,70.2 2020-09-12 02:00:00,2020,256,1,13,0,-8,70.2 2020-09-12 03:00:00,2020,256,2,13,0,-7,70.2 2020-09-12 04:00:00,2020,256,3,13,0,-5,70.2 2020-09-12 05:00:00,2020,256,4,13,0,-5,70.2 2020-09-12 06:00:00,2020,256,5,13,0,-8,70.2 2020-09-12 07:00:00,2020,256,6,20,0,-8,70.2 2020-09-12 08:00:00,2020,256,7,20,0,-7,70.2 2020-09-12 09:00:00,2020,256,8,20,0,-8,70.2 2020-09-12 10:00:00,2020,256,9,13,0,-8,70.2 2020-09-12 11:00:00,2020,256,10,13,0,-2,70.2 2020-09-12 12:00:00,2020,256,11,13,0,1,70.2 2020-09-12 13:00:00,2020,256,12,3,0,1,70.2 2020-09-12 14:00:00,2020,256,13,3,0,1,70.2 2020-09-12 15:00:00,2020,256,14,3,0,-2,70.2 2020-09-12 16:00:00,2020,256,15,7,0,-5,70.2 2020-09-12 17:00:00,2020,256,16,7,0,-4,70.2 2020-09-12 18:00:00,2020,256,17,7,0,-2,70.2 2020-09-12 19:00:00,2020,256,18,13,0,0,70.2 2020-09-12 20:00:00,2020,256,19,13,0,-1,70.2 2020-09-12 21:00:00,2020,256,20,13,0,-3,70.2 2020-09-12 22:00:00,2020,256,21,10,0,-5,70.2 2020-09-12 23:00:00,2020,256,22,10,0,-8,70.2 2020-09-13 00:00:00,2020,256,23,10,0,-9,70.2 2020-09-13 01:00:00,2020,257,0,10,0,-7,70.6 2020-09-13 02:00:00,2020,257,1,10,0,-8,70.6 2020-09-13 03:00:00,2020,257,2,10,0,-11,70.6 2020-09-13 04:00:00,2020,257,3,13,0,-11,70.6 2020-09-13 05:00:00,2020,257,4,13,0,-6,70.6 2020-09-13 06:00:00,2020,257,5,13,0,-5,70.6 2020-09-13 07:00:00,2020,257,6,13,0,-6,70.6 2020-09-13 08:00:00,2020,257,7,13,0,-9,70.6 2020-09-13 09:00:00,2020,257,8,13,0,-8,70.6 2020-09-13 10:00:00,2020,257,9,3,0,-6,70.6 2020-09-13 11:00:00,2020,257,10,3,0,-3,70.6 2020-09-13 12:00:00,2020,257,11,3,0,-2,70.6 2020-09-13 13:00:00,2020,257,12,13,0,0,70.6 2020-09-13 14:00:00,2020,257,13,13,0,2,70.6 2020-09-13 15:00:00,2020,257,14,13,0,0,70.6 2020-09-13 16:00:00,2020,257,15,17,0,1,70.6 2020-09-13 17:00:00,2020,257,16,17,0,1,70.6 2020-09-13 18:00:00,2020,257,17,17,0,9,70.6 2020-09-13 19:00:00,2020,257,18,13,0,8,70.6 2020-09-13 20:00:00,2020,257,19,13,0,8,70.6 2020-09-13 21:00:00,2020,257,20,13,0,12,70.6 2020-09-13 22:00:00,2020,257,21,30,0,8,70.6 2020-09-13 23:00:00,2020,257,22,30,0,8,70.6 2020-09-14 00:00:00,2020,257,23,30,0,9,70.6 2020-09-14 01:00:00,2020,258,0,33,2,4,69.7 2020-09-14 02:00:00,2020,258,1,33,2,-10,69.7 2020-09-14 03:00:00,2020,258,2,33,2,-19,69.7 2020-09-14 04:00:00,2020,258,3,33,2,-24,69.7 2020-09-14 05:00:00,2020,258,4,33,2,-35,69.7 2020-09-14 06:00:00,2020,258,5,33,2,-34,69.7 2020-09-14 07:00:00,2020,258,6,23,2,-29,69.7 2020-09-14 08:00:00,2020,258,7,23,2,-26,69.7 2020-09-14 09:00:00,2020,258,8,23,2,-29,69.7 2020-09-14 10:00:00,2020,258,9,27,2,-15,69.7 2020-09-14 11:00:00,2020,258,10,27,2,-10,69.7 2020-09-14 12:00:00,2020,258,11,27,2,-6,69.7 2020-09-14 13:00:00,2020,258,12,30,2,-12,69.7 2020-09-14 14:00:00,2020,258,13,30,2,-13,69.7 2020-09-14 15:00:00,2020,258,14,30,2,-10,69.7 2020-09-14 16:00:00,2020,258,15,10,2,-9,69.7 2020-09-14 17:00:00,2020,258,16,10,2,-8,69.7 2020-09-14 18:00:00,2020,258,17,10,2,-6,69.7 2020-09-14 19:00:00,2020,258,18,7,2,-7,69.7 2020-09-14 20:00:00,2020,258,19,7,2,-8,69.7 2020-09-14 21:00:00,2020,258,20,7,2,-10,69.7 2020-09-14 22:00:00,2020,258,21,20,2,-12,69.7 2020-09-14 23:00:00,2020,258,22,20,2,-14,69.7 2020-09-15 00:00:00,2020,258,23,20,2,-17,69.7 2020-09-15 01:00:00,2020,259,0,23,0,-17,69.6 2020-09-15 02:00:00,2020,259,1,23,0,-18,69.6 2020-09-15 03:00:00,2020,259,2,23,0,-16,69.6 2020-09-15 04:00:00,2020,259,3,20,0,-17,69.6 2020-09-17 00:00:00,2020,260,23,3,0,-15,70.2 

Answer: The following code is an adaptation of the excellent answer by @Muhammed Yunus. This updated version organizes the management of space weather data into a Class called SpaceWeather. A more detailed discussion of the changes is at my blog Visualizing Space Weather Data: From Procedural to Object-Oriented Approach. Key enhancements include:  Refactoring: The SpaceWeather class bundles related data and methods. The load_and_clean_data method loads and cleans data, and plot_data manages plotting.  Modularity: Separate methods are for different plot types (imshow, pcolormesh, contourf, plot_surface).  Type Hints: All function parameters and return types employ type hints.  Efficiency: plot_type == 'plot_surface' in this answer resulted in an unused figure, which is avoided in plot_surface.  Code Comments and Docstrings: Functionality is described by detailed comments and docstrings.  PEP8 Compliance: The code follows the PEP8 style guide.    Tested with:  python version: 3.12.0 pandas version: 2.2.1 numpy version: 1.26.4 matplotlib version: 3.8.1    import pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib.dates as mdates from typing import Dict, Union import matplotlib.figure import matplotlib.axes class SpaceWeather: def __init__(self, file_path: str): """ Initialize the SpaceWeather class. Parameters: file_path (str): The path to the CSV file containing the data. """ self.file_path = file_path self.df = None self.img_data = None self.labels = None self.dates = None def load_and_clean_data(self): """ Load and clean the space weather data. The code for which is from https://stackoverflow.com/a/78294905/7758804 """ # Load the necessary columns, parse dates, skip header, and rename columns self.df = pd.read_csv( self.file_path, parse_dates=[0], skiprows=1, usecols=[0, 4, 6], names=["date", "kp", "dst"], header=0, ) # Extract day of year and hour into new columns self.df["day_of_year"] = self.df["date"].dt.day_of_year # new columns self.df["hour"] = self.df["date"].dt.hour # Add event column self.df["event"] = "" self.df.loc[(self.df.kp > 40) | (self.df.dst < -30), "event"] = "S" self.df.loc[self.df.date == pd.Timestamp("2020/09/01 01:00"), "event"] = "E" # Create image data self.img_data = self.df.pivot_table( index="hour", columns="day_of_year", values="dst" ).values # Create labels to be used as annotations self.labels = self.df.pivot( index="hour", columns="day_of_year", values="event" ).values # Create date range for x-axis self.dates = pd.date_range( start=self.df.date.min(), end=self.df.date.max() + pd.offsets.Day(), freq="D", inclusive="both", ) def plot_data(self, plot_type: str = "imshow"): """ Plot the space weather data. The code for plotting is from https://stackoverflow.com/a/78294536/7758804 Parameters: plot_type (str): The type of plot to create. Options are 'imshow', 'pcolormesh', 'contourf', 'plot_surface'. """ common_params: Dict[str, Union[int, str]] = dict( vmin=-40, vmax=20, cmap="jet_r" ) # Create meshgrid for non-imshow plots if plot_type != "imshow": x, y = np.meshgrid( mdates.date2num(self.dates), range(self.img_data.shape[0]) ) # Plot data based on a plot type if plot_type == "imshow": self.plot_imshow(common_params) elif plot_type == "pcolormesh": self.plot_pcolormesh(x, y, common_params) elif plot_type == "contourf": self.plot_contourf(x, y, common_params) elif plot_type == "plot_surface": self.plot_surface(x, y, common_params) def plot_imshow(self, common_params: Dict[str, Union[int, str]]): """ Plot the space weather data using imshow. Parameters: common_params (Dict[str, Union[int, str]]): Common parameters for the plot. """ f, ax = plt.subplots(figsize=(11, 3)) im = ax.imshow( self.img_data, interpolation="none", aspect="auto", origin="lower", extent=( mdates.date2num(self.dates[0] - pd.offsets.Hour(12)), mdates.date2num(self.dates[-1] + pd.offsets.Hour(12)), float(self.df["hour"].min()), float(self.df["hour"].max()), ), **common_params, ) self.format_plot(f, im, ax, "imshow") def plot_pcolormesh(self, x: np.ndarray, y: np.ndarray, common_params: Dict[str, Union[int, str]]): """ Plot the space weather data using pcolormesh. Parameters: x (np.ndarray): The X coordinates of the meshgrid. y (np.ndarray): The Y coordinates of the meshgrid. common_params (Dict[str, Union[int, str]]): Common parameters for the plot. """ f, ax = plt.subplots(figsize=(11, 3)) im = ax.pcolormesh(x, y, self.img_data, **common_params) self.format_plot(f, im, ax, "pcolormesh") def plot_contourf(self, x: np.ndarray, y: np.ndarray, common_params: Dict[str, Union[int, str]]): """ Plot the space weather data using contourf. Parameters: x (np.ndarray): The X coordinates of the meshgrid. y (np.ndarray): The Y coordinates of the meshgrid. common_params (Dict[str, Union[int, str]]): Common parameters for the plot. """ f, ax = plt.subplots(figsize=(11, 3)) im = ax.contourf(x, y, self.img_data, levels=10, **common_params) self.format_plot(f, im, ax, "contourf") def plot_surface(self, x: np.ndarray, y: np.ndarray, common_params: Dict[str, Union[int, str]]): """ Plot the space weather data using plot_surface. Parameters: x (np.ndarray): The X coordinates of the meshgrid. y (np.ndarray): The Y coordinates of the meshgrid. common_params (Dict[str, Union[int, str]]): Common parameters for the plot. """ f = plt.figure(figsize=(11, 11)) ax = f.add_subplot(projection="3d", proj_type="persp", focal_length=0.2) ax.view_init(azim=79, elev=25) ax.set_box_aspect(aspect=(3, 2, 1.5), zoom=0.95) im = ax.plot_surface(x, y, self.img_data, **common_params) ax.contourf( x, y, self.img_data, levels=10, zdir="z", offset=-35, alpha=0.3, **common_params, ) ax.contour( x, y, self.img_data, levels=8, zdir="z", offset=24, alpha=0.5, linewidths=3, **common_params, ) ax.set_zlabel("Dst") ax.invert_xaxis() # Orders the dates from left to right ax.invert_yaxis() # Orders the hours from front to back self.format_plot(f, im, ax, "plot_surface") def format_plot(self, f: matplotlib.figure.Figure, im: matplotlib.image.AxesImage, ax: matplotlib.axes.Axes, plot_type: str): """ Format the plot. Parameters: f (matplotlib.figure.Figure): The figure. im (matplotlib.image.AxesImage): The image. ax (matplotlib.axes.Axes): The axes. plot_type (str): The type of plot. """ # Add labels for (row, col), label in np.ndenumerate(self.labels): if plot_type == "plot_surface": break # skip labels on 3d plot for simplicity if type(label) is not str: continue ax.text( self.dates[col] - pd.offsets.Hour(6), row, label, fontsize=9, fontweight="bold", ) # Format x-axis with dates ax.set_xticks(self.dates) ax.xaxis.set_major_formatter(mdates.DateFormatter(fmt="%b %d")) ax.xaxis.set_major_locator(mdates.DayLocator(interval=5)) # Tick every 5 days ax.tick_params(axis="x", rotation=90) # Format y axis ax.set_yticks([0, 6, 12, 18, 23]) ax.set_ylabel("UT") # Add colorbar aspect, fraction = (10, 0.15) if plot_type != "plot_surface" else (5, 0.05) f.colorbar(im, aspect=aspect, fraction=fraction, pad=0.01, label="nT") # Add title ax.set_title(f"Dst\n(plot type: {plot_type})", fontweight="bold") # Adjust layout plt.tight_layout() # Save the plot plt.savefig(f"{plot_type}_plot.png", dpi=300) # Show the plot plt.show() if __name__ == "__main__": sw = SpaceWeather("spaceWeather.csv") sw.load_and_clean_data() for plot_type in ["imshow", "pcolormesh", "contourf", "plot_surface"]: print(f"Plotting with plot type: {plot_type}") sw.plot_data(plot_type)