|
| 1 | +import matplotlib.pyplot as plt |
| 2 | +import numpy as np |
| 3 | +import seaborn as sns |
| 4 | + |
| 5 | +# New categories representing mode changes |
| 6 | +categories = ['Approach to Grasp', 'Grasp to Prepare', 'Prepare to Pull'] |
| 7 | +agents = ['DP-S', 'DP-M-AM'] |
| 8 | + |
| 9 | +# Mean times for each agent and mode change category |
| 10 | +mean_times = { |
| 11 | + 'DP-S': [8.5, 7.8, 6.9], |
| 12 | + 'DP-M-AM': [9.2, 8.3, 7.1] |
| 13 | +} |
| 14 | + |
| 15 | +# Standard errors for each agent and mode change category |
| 16 | +std_errors = { |
| 17 | + 'DP-S': [1.2, 1.1, 1.0], |
| 18 | + 'DP-M-AM': [1.5, 1.3, 1.2] |
| 19 | +} |
| 20 | + |
| 21 | +# Set Seaborn style and context for aesthetics |
| 22 | +sns.set(style='white', context='talk') |
| 23 | + |
| 24 | +# Create the figure and axes |
| 25 | +fig, ax = plt.subplots(figsize=(10, 6)) |
| 26 | + |
| 27 | +# Set up the bar positions |
| 28 | +x = np.arange(len(categories)) # Label locations |
| 29 | +width = 0.25 # Width of the bars |
| 30 | + |
| 31 | +# Plot the bars for 'DP-S' and 'DP-M-AM' using specified colors |
| 32 | +rects1 = ax.bar( |
| 33 | + x - width / 2, # Positions for DP-S bars |
| 34 | + mean_times['DP-S'], |
| 35 | + width, |
| 36 | + yerr=std_errors['DP-S'], |
| 37 | + capsize=5, |
| 38 | + label='DP-S', |
| 39 | + color='#a6cee3', # First color |
| 40 | + edgecolor='black' |
| 41 | +) |
| 42 | + |
| 43 | +rects2 = ax.bar( |
| 44 | + x + width / 2, # Positions for DP-M-AM bars |
| 45 | + mean_times['DP-M-AM'], |
| 46 | + width, |
| 47 | + yerr=std_errors['DP-M-AM'], |
| 48 | + capsize=5, |
| 49 | + label='DP-M-AM', |
| 50 | + color='#b2df8a', # Second color |
| 51 | + edgecolor='black' |
| 52 | +) |
| 53 | + |
| 54 | +# Customize labels and title |
| 55 | +ax.set_xlabel('Mode Change Stages', fontsize=21) |
| 56 | +ax.set_ylabel('Time Taken (s)', fontsize=21) |
| 57 | +ax.set_title('Comparison of Time Taken for Mode Changes', fontsize=24) |
| 58 | +ax.set_xticks(x) |
| 59 | +ax.set_xticklabels(categories, fontsize=18) # Increased fontsize for category labels |
| 60 | +ax.legend(title='', fontsize=16) |
| 61 | + |
| 62 | +# Set y-axis limits and ticks |
| 63 | +max_y = max( |
| 64 | + max(mean_times['DP-S']), |
| 65 | + max(mean_times['DP-M-AM']) |
| 66 | +) + max( |
| 67 | + max(std_errors['DP-S']), |
| 68 | + max(std_errors['DP-M-AM']) |
| 69 | +) + 2 |
| 70 | +ax.set_ylim(0, max_y) |
| 71 | + |
| 72 | +# Add ticks on the y-axis with smaller intervals |
| 73 | +ax.set_yticks(np.arange(0, max_y + 1, 2)) # Ticks every 2 units |
| 74 | + |
| 75 | +# Optionally, add minor ticks for even finer granularity |
| 76 | +ax.yaxis.set_minor_locator(plt.MultipleLocator(0.5)) # Minor ticks every 0.5 unit |
| 77 | +ax.grid(visible=True, which='major', axis='y', linestyle='--', alpha=0.7) # Add grid lines for major ticks |
| 78 | +ax.grid(visible=True, which='minor', axis='y', linestyle=':', alpha=0.4) # Add grid lines for minor ticks |
| 79 | + |
| 80 | +# Remove spines for a cleaner look |
| 81 | +sns.despine(ax=ax) |
| 82 | + |
| 83 | +# Adjust layout for tightness |
| 84 | +plt.tight_layout() |
| 85 | + |
| 86 | +# Display the plot |
| 87 | +plt.show() |
0 commit comments