Untitled
unknown
plain_text
9 days ago
4.0 kB
3
Indexable
Of course, here's a Python solution using matplotlib to visualize your aircraft height data: ```python import matplotlib.pyplot as plt import numpy as np def visualize_aircraft_heights(height_data): """ Visualize aircraft height data where: - keys are heights (integers) - values are lists of aircraft at that height Parameters: height_data (dict): Dictionary with heights as keys and lists of aircraft as values """ # Sort heights to ensure they're in ascending order heights = sorted(height_data.keys()) # Get all unique aircraft IDs all_aircraft = set() for aircraft_list in height_data.values(): all_aircraft.update(aircraft_list) all_aircraft = sorted(list(all_aircraft)) # Create a figure with two subplots fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 10)) # First plot: Count of aircraft at each height counts = [len(height_data[h]) for h in heights] ax1.plot(heights, counts, marker='o', linestyle='-', linewidth=2) ax1.set_title('Number of Aircraft at Each Height') ax1.set_xlabel('Height (ft)') ax1.set_ylabel('Count of Aircraft') ax1.grid(True) # Second plot: Individual aircraft presence at different heights # Create a matrix to represent aircraft presence presence_matrix = np.zeros((len(all_aircraft), len(heights))) for i, height in enumerate(heights): aircraft_at_height = height_data[height] for j, aircraft in enumerate(all_aircraft): if aircraft in aircraft_at_height: presence_matrix[j, i] = 1 # Plot each aircraft's presence for i, aircraft in enumerate(all_aircraft): ax2.step(heights, presence_matrix[i], where='mid', label=aircraft, linewidth=2) ax2.set_title('Individual Aircraft Presence by Height') ax2.set_xlabel('Height (ft)') ax2.set_ylabel('Present (1) / Absent (0)') ax2.set_yticks([0, 1]) ax2.set_ylim(-0.1, 1.1) ax2.legend(loc='center left', bbox_to_anchor=(1, 0.5)) ax2.grid(True) plt.tight_layout() plt.show() # Bonus: Display a heatmap view fig, ax3 = plt.subplots(figsize=(12, 6)) im = ax3.imshow(presence_matrix, aspect='auto', cmap='Blues') # Set ticks and labels ax3.set_xticks(np.arange(len(heights))) ax3.set_xticklabels(heights) ax3.set_yticks(np.arange(len(all_aircraft))) ax3.set_yticklabels(all_aircraft) ax3.set_title('Aircraft Presence Heatmap') ax3.set_xlabel('Height (ft)') ax3.set_ylabel('Aircraft') # Add a colorbar cbar = plt.colorbar(im) cbar.set_ticks([0, 1]) cbar.set_ticklabels(['Absent', 'Present']) plt.xticks(rotation=45) plt.tight_layout() plt.show() # Example usage if __name__ == "__main__": # Sample data aircraft_heights = { 0: ['Aircraft1', 'Aircraft2', 'Aircraft3'], 1000: ['Aircraft1', 'Aircraft2', 'Aircraft4', 'Aircraft5'], 2000: ['Aircraft1', 'Aircraft3', 'Aircraft4'], 3000: ['Aircraft2', 'Aircraft3', 'Aircraft5'], 4000: ['Aircraft1', 'Aircraft4'], 5000: ['Aircraft3', 'Aircraft5'], 6000: ['Aircraft1', 'Aircraft2'], 7000: ['Aircraft4'], 8000: ['Aircraft1', 'Aircraft3', 'Aircraft5'], 9000: ['Aircraft2'], 10000: ['Aircraft1', 'Aircraft3', 'Aircraft4'] } visualize_aircraft_heights(aircraft_heights) ``` This code creates three visualizations: 1. A line chart showing the count of aircraft at each height 2. A step chart showing the presence/absence of each aircraft at different heights 3. A heatmap visualization showing all aircraft and their presence at each height To use it with your data, just replace the `aircraft_heights` dictionary with your own. The keys should be integers representing heights, and the values should be lists of aircraft identifiers at those heights.
Editor is loading...
Leave a Comment