Plot boxes as lines, with delta on x axis and averages on y axis
- User
Plot boxes as lines, with delta on x axis and averages on y axis
Assistant
Here’s the updated code to plot the data with delta values on the x-axis and averages on the y-axis. Each box (from
box_starttobox_end) will be represented as a line for each delta column. The legend will have two columns and be positioned to the right to avoid interference.import pandas as pd import matplotlib.pyplot as plt import numpy as np # Load the TSV file df = pd.read_csv('average_deltas_by_box.tsv', sep='\t') # Extract relevant columns box_start = df['box_start'].replace('-inf', -np.inf) # Convert '-inf' back to -inf for clarity box_end = df['box_end'] delta_cols = [col for col in df.columns if col.startswith('delta')] # Prepare for plotting plt.figure(figsize=(12, 6)) # Set figure size # Generate a color map for multiple lines num_lines = len(delta_cols) colors = plt.cm.tab20b(np.linspace(0, 1, num_lines)) # Use 'tab20b' for distinct colors # Plot each box as a line for every delta column for i, col in enumerate(delta_cols): y_values = df[col] # Average delta values (y-axis) for j in range(len(y_values)): plt.plot([box_start[j], box_end[j]], [y_values[j], y_values[j]], color=colors[i], label=col if j == 0 else None) # Label only once per delta # Add labels, title, and legend plt.xlabel('Delta Value') plt.ylabel('Average Value') plt.title('Average Values by Box and Delta') # Add legend with two columns and move it to the right plt.legend(loc='center left', bbox_to_anchor=(1, 0.5), ncol=2, fontsize='small', title='Delta Columns') plt.grid(True) # Add grid for readability plt.tight_layout() # Adjust layout to make space for the legend # Save the plot plt.savefig('averages_by_box_and_delta.png', bbox_inches='tight') plt.show() print(f"Plot saved as 'averages_by_box_and_delta.png'.")Key Changes:
-
Axes Swap:
- Delta values (
box_startandbox_end) are now on the x-axis. - Average values (from delta columns) are on the y-axis.
- Delta values (
-
Box Representation:
- Each box is plotted as a horizontal line for every delta column, spanning from
box_starttobox_end.
- Each box is plotted as a horizontal line for every delta column, spanning from
-
Legend:
- Legend has two columns and is positioned to the right using
bbox_to_anchor. - Each delta column is labeled only once in the legend.
- Legend has two columns and is positioned to the right using
-
Colormap:
- Uses
'tab20b'for distinct colors, suitable for many lines.
- Uses
-
Output:
- Plot is saved as
averages_by_box_and_delta.png.
- Plot is saved as
This visualization clearly shows how average values vary across delta columns for each box range.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.