I'm trying to plot some data, which I can easily print out. When I plot the data in any way a blank plot appears. I dont fully understand why this is happening as the dataframe is full of data, and the plotting doesnt raise any errors. Below is my code. I've also attached an image of the blank/empty plot below.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
# Read the data from "Cosmic.csv"
df = pd.read_csv("Cosmic.csv")
# Filter rows for a specific day
specific_day = '2021-08-13' # Replace this with the desired date
specific_day_df = df[df['date'] == specific_day]
# Define the latitude and longitude of the specific point
specific_lat = 15 # Replace with actual latitude
specific_lon = 48 # Replace with actual longitude
# Create a box around the specific point
latitude_range = [specific_lat - 2000, specific_lat + 2000]
longitude_range = [specific_lon - 2000, specific_lon + 200]
box_df = specific_day_df[
(specific_day_df['Latitude'] >= latitude_range[0]) & (specific_day_df['Latitude'] <= latitude_range[1]) &
(specific_day_df['Longitude'] >= longitude_range[0]) & (specific_day_df['Longitude'] <= longitude_range[1])]
# Create a heatmap
plt.figure(figsize=(12, 6))
# altitude_bins = pd.interval_range(start=filtered_data['Altitude'].min(),
# end=filtered_data['Altitude'].max() + 10,
# freq=10)
# df['altitude_bin'] = pd.cut(filtered_data['Altitude'], bins=altitude_bins)
# mean_density = df.groupby(['altitude_bin', 'date_bin'])['Electron_Density'].mean().unstack()
# Convert bin labels to dates for plotting
# mean_density.columns = mean_density.columns.map(lambda x: x.mid.strftime('%m/%d'))
print("Not Pivoted Data already filtered:")
print(box_df)
print("Pivoted Data for Plotting:")
print(box_df.pivot_table(values='Electron_Density', index='Altitude', columns='date', aggfunc='mean'))
sns.heatmap(box_df.pivot_table(values='Electron_Density', index='Altitude', columns='date', aggfunc='mean'),
cmap='jet', linewidths=0.5)
# sns.heatmap(mean_density)
plt.axhline(y=specific_day_df['Altitude'].min(), linestyle='--', color='k')
plt.axvline(x=specific_day_df['date'].iloc[0], linestyle='--', color='k')
plt.xlabel('Date', fontweight='bold')
plt.ylabel('Altitude in km', fontweight='bold')
plt.title('Electron Density Heatmap', fontweight='bold')
plt.gca().invert_yaxis()
plt.show()
Here is the output stream and blank plot:
Not Pivoted Data already filtered:
Unnamed: 0.3 Unnamed: 0.2 Unnamed: 0.1 Unnamed: 0 Day Latitude \
277461 277461 14139589 14140062 14140062 225 15.002479
277464 277464 14139592 14140065 14140065 225 15.204655
277465 277465 14139593 14140066 14140066 225 15.272005
... ... ... ... ... ... ...
306369 306369 15750990 15751793 15751793 225 15.117569
306373 306373 15750994 15751797 15751797 225 15.022529
Longitude Altitude Electron_Density TEC \
277461 -51.131245 463.24896 49245.555 10.842576
277465 -51.455490 467.51334 55565.457 10.787354
... ... ... ... ...
306369 -83.494180 492.12985 106565.130 14.947100
306373 -83.278440 496.97370 102364.370 13.715951
Occultation_Azimuth date Altitude_Bin mean_density
277461 -141.431850 2021-08-13 [460.001, 470.001) 96827.112941
277462 -141.466920 2021-08-13 [460.001, 470.001) 96827.112941
... ... ... ... ...
306373 38.950077 2021-08-13 [490.001, 500.001) 74717.005703
[28913 rows x 14 columns]
Pivoted Data for Plotting:
date 2021-08-13
Altitude
100.04126 9397.4210
100.14729 147425.3300
100.18883 9091.6930
... ...
546.82135 26094.6430
546.87100 10054.5460
546.92224 2458.5593